Reputation: 3359
I cannot unwrap an optional NSDictionary. I am using NSDictionary because that is what I am returned when loading a plist from a file path.
var dict: NSDictionary? = NSDictionary(contentsOfFile: getFontPath())
assert(dict != nil, "Top level dictionary from plist can't be nil")
var fontArray = dict!objectForKey("fonts") as [NSDictionary]
The compiler is not recognizing dict! as an unwrap - tells me I should separate sequences by a ;
What is the problem and solution?
Upvotes: 0
Views: 1731
Reputation: 10224
You're missing the attribute accessor (ie, the dot) after the exclamation point:
var fontArray = dict!.objectForKey("fonts") as [NSDictionary]
^
Depending on what you're doing, it might make more sense to use if let
, eg:
if let unwrappedDict = dict as? NSDictionary {
}
Upvotes: 2