Nils Wasell
Nils Wasell

Reputation: 997

Check if array value is equal to string

I am getting a result from my API in the form of a NSArray:

func JSONAPIResults(results: NSArray) {
        dispatch_async(dispatch_get_main_queue(), {
            self.loginResult = results
        })
    }

My question is, how do i use a IF Statement in order to check it against a String? For example, checking if self.loginResult[0]["result"] is equal to "Success"

Cheers

Upvotes: 0

Views: 526

Answers (1)

Undo
Undo

Reputation: 25687

If you know that the object at that point in the JSON will always be a string, try casting the value to String before comparing it to get rid of the cannot invoke == with argument list error:

if (self.loginResult[0]["result"] as String) == "Success"?
{
    ...
}

Upvotes: 1

Related Questions