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.

enter image description here

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

Popular posts from this blog

javascript - How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)? -

javascript - How do I find how many occurences are there of a highlighted string, and which occurence is it? -

java - Reading data from multiple zip files and combining them to one -