Ios 我的url不返回nil,而是swift中的空字符串
下面是基于url的代码,我需要获取图像。 但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
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")
}