Assuming I have a dictionary like this:
let path = NSBundle.mainBundle().pathForResource("books", ofType: "plist")
let dict = NSDictionary(contentsOfFile: path)
let books = dict.objectForKey("Books") as [[String:AnyObject]]
let rnd = Int(arc4random_uniform((UInt32(books.count))))
let bookData = books[rnd]
Why does it work?
let author = bookData["author"]! as String
But this causes a crash:
let chapterNum = bookData["chapterNum"]! as Int
The following is indicated in the bookData log:
bookData: [content: whatever, author: John Doe, tags: (
tagA,
tagB
), chapterNum: 5]
source
share