I am parsing a JSON response and trying to check if one of my keys is null. How would I go about this? I have the following:
var routingNumber = (dic.value(forKey: "result") as! NSDictionary).value(forKey: "routingNumber") as! String
and this returns:
Could not cast value of type 'NSNull' (0x107d238c8) to 'NSString' (0x107329c40).
How would I check if the value is NSNULL?
if( something != NSNULL){
do something
}else{
do something else
}
NSDictionary
in Swift. Use a Swift dictionary. Do not usevalue(forKey:)
to get a value unless you have a specific reason to be using KVC (which you don't have in this case). – Ribal