Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/100.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/8/swift/17.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 我的url不返回nil,而是swift中的空字符串_Ios_Swift_Url - Fatal编程技术网

Ios 我的url不返回nil,而是swift中的空字符串

Ios 我的url不返回nil,而是swift中的空字符串,ios,swift,url,Ios,Swift,Url,下面是基于url的代码,我需要获取图像。 但url不是nil,而是双引号“”或空字符串。 因此,我如何处理swift中双引号的检查 DispatchQueue.global(qos: .background).async { [weak self] () -> Void in if let url = NSURL(string: arr[indexPath.row].imgl){ if let data = NSData(contentsOf: url

下面是基于url的代码,我需要获取图像。 但url不是nil,而是双引号“”或空字符串。 因此,我如何处理swift中双引号的检查

DispatchQueue.global(qos: .background).async { [weak self] () -> Void in

    if let url = NSURL(string: arr[indexPath.row].imgl){

             if let data = NSData(contentsOf: url as URL) {

                  DispatchQueue.main.async {
                     cell.img.image = UIImage(data: data as Data)!
                }
              }
          }
   }
如果url为“”,则应转到其他部分。

将其转换为:

NSURL(string: arr[indexPath.row].imgl)
为此:

URL(string: arr[indexPath.row].imgl)

如何处理swift中双引号的检查


你能给我们看一下你的json吗?@pkc456-url是数组中存储的字符串-arr(arr[indepath.row].imgl)共享你的数组所持有的字典你的问题在arr中,请给出arr,但是
[weak self]
是没有意义的<代码>调度队列闭包不会导致保留周期。不要在Swift中使用
NSURL
NSData
,请使用本机
URL
Data
。并且永远不要从远程URL加载包含同步
数据(contentsOf
)的数据,即使在后台线程中也不要加载。
if myString.isEmpty {
   print("its empty. Means it is just two double quotes without anything between")
}