manisha upadhyay
manisha upadhyay

Reputation: 81

my url does not return nil but empty string in swift

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

Answers (1)

Mojtaba Hosseini
Mojtaba Hosseini

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

Related Questions