Tyler Patrick
Tyler Patrick

Reputation: 57

Parse checking if nil

I have some code that pulls users based on what they type on a login view. I am trying to check if a specific field is blank (nil) with something along the following

for user in users{
   if user["secretkey"] == nil {
   query.getObjectInBackgroundWithId(user.objectId) {

However, when the column "secretkey" is in fact nil, tested with println(user["secretkey"], the if statement continues to its default.

Upvotes: 0

Views: 277

Answers (2)

Tyler Patrick
Tyler Patrick

Reputation: 57

Fixed it in my situation by declaring it as a variable first using the following.

let secretKeyParse = user["secretkey"] as String?
              if secretKeyParse == nil {

Upvotes: 0

Wain
Wain

Reputation: 119031

Use the form:

for user in users {
    if let secretKey = user["secretkey"] {
        query.getObjectInBackgroundWithId(user.objectId) {
    }
}

(you can also then use secretKey directly inside the if block if you wanted to)

Upvotes: 2

Related Questions