Noah-1
Noah-1

Reputation: 396

Check if Parse.com field is undefined/nil ?

In parse when you have a field for data, let's say a string, to check if there is no data in it, you have to click on the field to remove the "undefined", then in Xcode do:

if(myString.isEmpty){/*do something*/}

If I try to simply compare it to nil, I get the error: "Binary operator "==" cannot be applied to operands of type string and nil"

I am making an app that retrieves several objects from Parse.com, I want to be able to constantly update my app from there, what I have not been able to figure out is how to add checks for a field that is undefined, sometimes I want to be able to leave some of the data fields undefined because not all of them are crucial, so how would I achieve this?

There is the same question here, but what the user asking used to solve his problem, did not work for me

Upvotes: 3

Views: 627

Answers (1)

suisied
suisied

Reputation: 426

you can do optional binding

if let name = employerProfileObject.valueForKey("name"){
      self.companyIndustry.text = "\(name.capitalizedString)"
}

it wont return an error if the field in parse is empty

Upvotes: 3

Related Questions