不兼容的指针类型将'NSURL * __ strong'发送到'NSString *'类型的参数

时间:2013-02-07 05:46:42

标签: iphone ios objective-c

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 *'

1 个答案:

答案 0 :(得分:1)

使用stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding

转换字符串
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]];