Reputation: 2322
I want to check if an object I get from the server is nil or not, if nil I want to use a placeholder image, if not nil I want to use the image from the url. Debugger says imageUrl is nil, but my code evaluates it as not nil.
the code always crash at
providerImg.sd_setImageWithURL(NSURL(string: GPProfiles[indexPath.row]["image"] as! String))
I have also tried this
let imageUrl = GPProfiles[indexPath.row]["image"]
if imageUrl != nil {
providerImg.sd_setImageWithURL(NSURL(string: GPProfiles[indexPath.row]["image"] as! String))
} else{
providerImg.image = UIImage(named: "placeholderImage.png")
}
How can I check if an object is nil ??? Thanks
Upvotes: 1
Views: 44
Reputation: 14030
try this:
if let imageUrl = GPProfiles[indexPath.row]["image"] as? String {
...
}
since your != nil
check does not seem to work here you get some more info about nil
, NULL
and NSNull
: nshipster.com/nil
Upvotes: 2