Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/106.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何加上「;http://quot;添加到字符串(如果缺少)_Ios_Objective C - Fatal编程技术网

Ios 如何加上「;http://quot;添加到字符串(如果缺少)

Ios 如何加上「;http://quot;添加到字符串(如果缺少),ios,objective-c,Ios,Objective C,我有一个字符串[currentweet pic],应该是图片的URL(从XML文件解析)。问题是一些链接缺少URL中的“http://”,因此一些图片不会出现。如何在缺少的地方添加“http://” 非常感谢您的帮助!thx我假设您在这里指的是NSString,而不是NSURL NSString *picURL = [currentTweet pic]; if (![picURL hasPrefix:@"http://"]) { picURL = [@"http://" stringBy

我有一个字符串
[currentweet pic]
,应该是图片的URL(从XML文件解析)。问题是一些链接缺少URL中的“http://”,因此一些图片不会出现。如何在缺少的地方添加“http://”


非常感谢您的帮助!thx

我假设您在这里指的是
NSString
,而不是
NSURL

NSString *picURL = [currentTweet pic];
if (![picURL hasPrefix:@"http://"]) {
    picURL = [@"http://" stringByAppendingString:picURL];
}

不确定twitter是否曾经使用
https
作为pic URL,但您可能还应该检查
https://
以确定。

您如何知道它应该是
http://
而不是
https://