关于iphone:向“ NSString *”类型的参数发送“ NSURL * __ strong”的不兼容指针类型

 2019-10-16 

Incompatible pointer types sending 'NSURL *__strong' to parameter of type 'NSString *'

1
2
3
4
5
6
NSString *urlString = [NSString stringWithFormat:@"http://shareaspetto.com/share/updateprofile.php?name=%@&gender=%@&email=%@&about_us=%@&id=%@&image=%@", nameString, genderString, emailString, aboutusString, idString, imgNameString];
NSLog(@"urlString = %@", urlString);
while ([urlString rangeOfString:@""].location != NSNotFound) {
    urlString = [urlString stringByReplacingOccurrencesOfString:@"" withString:@"%20"];
}    
NSString *rplyString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString]];

当我编译以上代码时,会出现警告Incompatible pointer types sending 'NSURL *__strong' to parameter of type 'NSString *'


stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding转换字符串

1
2
3
4
5
6
7
8
NSString *urlString = [NSString stringWithFormat:@"http://shareaspetto.com/share/updateprofile.php?name=%@&gender=%@&email=%@&about_us=%@&id=%@&image=%@", nameString, genderString, emailString, aboutusString, idString, imgNameString];
urlString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]
NSLog(@"urlString = %@", urlString);
while ([urlString rangeOfString:@""].location != NSNotFound) {
    urlString = [urlString stringByReplacingOccurrencesOfString:@"" withString:@"%20"];
}

NSString *rplyString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString]];