swift - NSMutableDictionary path "unexpectedly found nil while unwrapping an Optional value" -
i have simple:
let documentspath = nssearchpathfordirectoriesindomains(.documentdirectory, .userdomainmask, true)[0] as! string let datapath = documentspath.stringbyappendingpathcomponent("images") let imagespath = datapath.stringbyappendingpathcomponent(filename) var dictionary = nsmutabledictionary(contentsoffile: imagespath)!
and after gets last line crashes , gives me ol'
fatal error: unexpectedly found nil while unwrapping optional value
the variable filename
declared var filename: string!
i'm unable write path well. doing wrong?
another potential issue in addition gnasher729's suggestion contentsoffile initializer nsdictionaries , subclasses:
return value:
an initialized dictionary—which might different original receiver—that contains dictionary @ path, or nil if there file error or if contents of file invalid representation of dictionary.
so if there issue dictionary, when force unwrap in line
var dictionary = nsmutabledictionary(contentsoffile: imagespath)!
it crash.
Comments
Post a Comment