I need your help. I have an NSURL object I get from this
NSURL *myImageUrls = [[feeds objectAtIndex:indexPath.row] objectForKey: @"url"];
if(myImageUrls == nil){
NSLog(@"URL empty %@", myImageUrls);
}
else{
//NSURL *url = imageUrls;
NSLog(@"Image URL:%@", myImageUrls);
}
The NSLog shows Image URL: meaning the myImageUrls is empty but the if statement never get printed. How do I get it to print if the NSURL object is empty. I have tried myImageUrls == null and [myImageUrls length] =0 but still the if block never get printed.
If your NSLog
prints "Image URL:" that doesn't indicate that your NSURL
is nil or null; it indicates that your NSURL
's string is empty. If your NSURL
was null but still executing that second conditional, your NSLog
would print: "Image URL: (null)" instead.
To check whether your NSURL
's string is empty (since it seems as if you're storing NSURL
's in all indexes of your array, but simply storing an NSURL
with an empty string at the "empty" indices), change your conditional to the following:
if(myImageUrls.absoluteString.length == 0){
NSLog(@"URL empty %@", myImageUrls);
}
else{
//NSURL *url = imageUrls;
NSLog(@"Image URL:%@", myImageUrls);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With