0

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

3
  • Have you tried simply self.loginResult[0]["result"] == "Success"? Commented Sep 22, 2014 at 18:34
  • Absolutley @Undo, this generates: Cannot invoke '==' with an argument list of type '($T8, StringLiteralConvertible)' Commented Sep 22, 2014 at 18:35
  • If you know that the object at that point in the JSON will always be a string, try if (self.loginResult[0]["result"] as String) == "Success"? Tell me if it works and I'll post an answer. Commented Sep 22, 2014 at 18:37

1 Answer 1

1

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"?
{
    ...
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.