Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSCFString absoluteURL exception

This is my code to retrieve data from a MySQL table using JSON:

//URL definition where php file is hosted

    int categoriaID = [[categoriaDescription objectForKey:@"idCategoria"] intValue];

    NSString *string = [NSString stringWithFormat:@"%d", categoriaID];
    NSLog(@"CATEGORIA ID STRING %@",string);
    NSMutableString *ms = [[NSMutableString alloc] initWithString:@"http://mujercanariasigloxxi.appgestion.eu/app_php_files/categoriaslist.php?id="];
    [ms appendString:string];
    // URL request
    NSLog(@"URL = %@",ms);
    NSURLRequest *request = [NSURLRequest requestWithURL:ms];
    //URL connection to the internet
    [[NSURLConnection alloc]initWithRequest:request delegate:self];

The URL logged is correct, but the app throws an exception:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString absoluteURL]: unrecognized selector sent to instance 

I guess the error should be in the above code, but I don't see why. Any help is welcome.

like image 841
mvasco Avatar asked Dec 08 '22 09:12

mvasco


1 Answers

I think your code is wrong.

NSURLRequest *request = [NSURLRequest requestWithURL:ms];

It should be change to:

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:ms]];

like image 121
Tan Vu Avatar answered Dec 11 '22 11:12

Tan Vu