Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

With iOS, how to check if URL is empty

I'm loading an JSON but i want to check of the "URL": "", in the json is empty sometimes the ID is empty how can i check?

if(URL == HOW TO CHECK IF EMPTY?)
{

}
else
{

}

Error:

*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 0 beyond bounds for empty array'
*** First throw call stack:
like image 825
Jones Avatar asked May 17 '12 13:05

Jones


2 Answers

Hmm, try

if ([URL isEqualToString:@"The URL?"]) {
like image 150
Blazer Avatar answered Oct 06 '22 19:10

Blazer


If the URL object is a string, you can use either,

if([string length] == 0) { //empty }

or

if([string isEqualToString:@""]) { // empty }

If the URL object is an NSURL, you can use:

if([[url absoluteString] isEqualToString:@""]) { //empty }
like image 33
Zack Brown Avatar answered Oct 06 '22 20:10

Zack Brown