Reputation: 63
I'm a newbie in iOS development. Sometimes my API server returns a nil
value. This is raising an error when I try to create a NSURL
instance.
Here is the condition:
NSString *tmpURL = nil;
NSURL *url = [NSURL URLFromString:tmpURL];
In this condition, it will make the app crash. I just want to make the url
variable nil, not raise an error.
Upvotes: 3
Views: 245
Reputation: 1034
How about:
NSString *tmpURL = nil;
NSURL *url = tmpUrl ? [NSURL URLFromString:tmpURL] : nil;
Upvotes: 6