Nata Mio
Nata Mio

Reputation: 2226

Unexpectedly found nil while unwrapping an Optional value - Plist

i am trying to read from propriety list using swift but im getting this error, and thats the code im using to read from my plist :

Arrays i'm using :

var recipeNames :[String] = []
var recipeImages :[String] = []
var recipeTime :[String] = []

In viewDidload :

 var path = NSBundle.mainBundle().pathForResource("recipes", ofType: "plist")
    var dict = NSDictionary(contentsOfFile: path!)
     recipeNames  = dict!.objectForKey("name")! as! [String]
     recipeImages  = dict!.objectForKey("image")! as! [String]
     recipeTime  = dict!.objectForKey("time")! as! [String]

Upvotes: 2

Views: 651

Answers (1)

AaoIi
AaoIi

Reputation: 8396

Seems to be no error in your code, Check that the arrays in plist has the same naming as in your code might be mistaken something with keys.

You can check that by right-click on plist and Open-as then choose source code

Like : objectForKey("name") called <key>name</key> objectForKey("image") called <key>image</key> objectForKey("time") called <key>time</key>

Upvotes: 4

Related Questions