jeudi 28 juillet 2016

Is there a difference between == true and != false in swift?

I had this code in my Swift App

func parseJSON() {

    let urlString = "http://ift.tt/2aAt1hi"

    if NSURL(string: urlString) == true {
        let url = NSURL(string: urlString)
        let data = try? NSData(contentsOfURL: url!, options: []) as NSData
        let json = NSData(data: data!)

// more code

However, even though the link actually worked and was true, the if statement was never met and it kept skipping it and moving to else. So I changed the code to

if NSURL(string: urlString) != false 

and it worked perfectly. I'm not sure why though?

Aucun commentaire:

Enregistrer un commentaire