null - Swift 'NilLiteralConvertible' error: Optional class type -
in storyviewcontroller.swift:
var story :story? if story != nil {...}// error: type uint8 doer not conform protocol 'nilliteralconvertible'
in story.swift:
class story { var title: string var content: string init(title: string, content: string) { self.title = title self.content = content } func description() -> string { homecoming title } class func loadstories(completion: ((array<story>?, nserrorpointer) -> void)!) { dispatch_async(dispatch_get_global_queue(dispatch_queue_priority_default, 0), { var error: nserrorpointer = nil allow path = nsbundle.mainbundle().bundlepath allow manager = nsfilemanager.defaultmanager() var stories = [story]() if allow contents = manager.contentsofdirectoryatpath(path, error: error) { error = nil file in contents { if file.hassuffix(".grm") { allow filepath = path.stringbyappendingpathcomponent(file string) allow title = file.stringbydeletingpathextension allow content = nsstring(contentsoffile: filepath, encoding: nsutf8stringencoding, error: error) allow story = story(title: title, content: content) if error != nil { break } stories.append(story) error = nil } } } stories.sort({ a, b in a.title < b.title }) dispatch_async(dispatch_get_main_queue(), { if error != nil { completion(nil, error) } else { completion(stories, nil) } }) }); } }
am write right? how can prepare error:"type uint8 doer not conform protocol 'nilliteralconvertible'" in storyviewcontroller.swift? lot!
more: want check whether story file empty. , if it's not, show info in view. code above ran before swift beta3 released. guess may new nilliteralconvertible protocal cause error.
/*************************************************/ download project http://cdn5.raywenderlich.com/wp-content/uploads/2014/09/grimm-swift.zip exercise bbs. if run version without modified you'll noticed error above. creator of project. /*************************************************/
use this
var story: story? story = story (title: "stack", content: "overflow") if story != nil { println("it's not nil!") } else { println("it's nil!") }
swift null optional
No comments:
Post a Comment