ios - Swift Casting on Pre iPhone 6 Devices -
for reason line of code crashing on pre iphone 6 devices:
var friendmatch = newdict.objectforkey("is_match") int
the dictionary generated json receive endpoint. json looks this:
"is_match" = 1;
i've tried:
var friendmatch: nsnumber = newdict.objectforkey("is_match") nsnumber
and app still crashes on line. crash log unhelpful.
any thoughts on why working on iphone 6 , 6+, not on older devices?
var friendmatch = newdict.objectforkey("is_match") int
you should not casting unconditionally. cast conditionally instead:
if let friendmatch = newdict.objectforkey("is_match") as? int { // ... }
now if cast fails won't crash.
Comments
Post a Comment