比较空的 NSURL
Comparing empty NSURL
我需要你的帮助。我有一个 NSURL 对象,我从这个
NSURL *myImageUrls = [[feeds objectAtIndex:indexPath.row] objectForKey: @"url"];
if(myImageUrls == nil){
NSLog(@"URL empty %@", myImageUrls);
}
else{
//NSURL *url = imageUrls;
NSLog(@"Image URL:%@", myImageUrls);
}
NSLog 显示图像 URL:意味着 myImageUrls 为空,但 if 语句永远不会打印。如果 NSURL 对象为空,我如何打印它。我试过 myImageUrls == null 和 [myImageUrls length] =0 但 if 块仍然没有打印出来。
NSURL 包含一个方法checkResourceIsReachableAndReturnError
NSURL *myURL = [NSURL URLWithString:string];
NSError *err;
if ([myURL checkResourceIsReachableAndReturnError:&err] == NO)
{
NSLog(@"resource not reachable");
}
如果您的 NSLog
输出 "Image URL:" 并不表示您的 NSURL
为 nil 或 null;它表明您的 NSURL
的 字符串 是空的。如果您的 NSURL
为 null 但仍在执行第二个条件,则您的 NSLog
将打印: "Image URL: (null)" 相反。
检查 NSURL
的字符串是否为空(因为看起来好像您在数组的所有索引中都存储了 NSURL
,但只是存储了一个 NSURL
在 "empty" 索引处使用空字符串),将条件更改为以下内容:
if(myImageUrls.absoluteString.length == 0){
NSLog(@"URL empty %@", myImageUrls);
}
else{
//NSURL *url = imageUrls;
NSLog(@"Image URL:%@", myImageUrls);
}
我需要你的帮助。我有一个 NSURL 对象,我从这个
NSURL *myImageUrls = [[feeds objectAtIndex:indexPath.row] objectForKey: @"url"];
if(myImageUrls == nil){
NSLog(@"URL empty %@", myImageUrls);
}
else{
//NSURL *url = imageUrls;
NSLog(@"Image URL:%@", myImageUrls);
}
NSLog 显示图像 URL:意味着 myImageUrls 为空,但 if 语句永远不会打印。如果 NSURL 对象为空,我如何打印它。我试过 myImageUrls == null 和 [myImageUrls length] =0 但 if 块仍然没有打印出来。
NSURL 包含一个方法checkResourceIsReachableAndReturnError
NSURL *myURL = [NSURL URLWithString:string];
NSError *err;
if ([myURL checkResourceIsReachableAndReturnError:&err] == NO)
{
NSLog(@"resource not reachable");
}
如果您的 NSLog
输出 "Image URL:" 并不表示您的 NSURL
为 nil 或 null;它表明您的 NSURL
的 字符串 是空的。如果您的 NSURL
为 null 但仍在执行第二个条件,则您的 NSLog
将打印: "Image URL: (null)" 相反。
检查 NSURL
的字符串是否为空(因为看起来好像您在数组的所有索引中都存储了 NSURL
,但只是存储了一个 NSURL
在 "empty" 索引处使用空字符串),将条件更改为以下内容:
if(myImageUrls.absoluteString.length == 0){
NSLog(@"URL empty %@", myImageUrls);
}
else{
//NSURL *url = imageUrls;
NSLog(@"Image URL:%@", myImageUrls);
}