Reputation: 81
below is the code where based on url I need to get the image. But url is not nil instead it is double quotes "" or empty string. Hence how do I handle check for double quotes in 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)!
}
}
}
}
if url is "" then it should go to else part.
Upvotes: 1
Views: 1656
Reputation: 120113
Convert this:
NSURL(string: arr[indexPath.row].imgl)
to this:
URL(string: arr[indexPath.row].imgl)
.
how do I handle check for double quotes in swift?
if myString.isEmpty {
print("its empty. Means it is just two double quotes without anything between")
}
Upvotes: 3