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 - ScrollTo Effect (href to div) -

javascript - ng-class not responding to change in model in Angular? -

javascript - document.registerElement extending HTMLInputElement prototype while using custom tag name to avoid implicit browser style -