Sally Peter Sally Peter - 1 year ago 77
Swift Question

Could not cast value of type 'NSNull' (0x10aa1b600) to 'NSString' (0x10b4dab48)

My json has googleplus links of restaurants and it shows null if restaurant does not have any googleplus link But I get error of as mentioned above.

if dict["googlepluslink"] != nil
{
self.googlepluslink.append((dict["googlepluslink"] as? String)!)
}
else
{
self.googlepluslink.append(("-" as? String)!)
}



Could not cast value of type 'NSNull' (0x10aa1b600) to 'NSString' (0x10b4dab48)

Answer Source

use if let or guard statement to check dict["googlepluslink"] is String or not and then according to that you can append your data like below

if let link = dict["googlepluslink"] as? String 
{ 
    self.googlepluslink.append(link)
} 
else {
    self.googlepluslink.append("-")
}