user3246980
user3246980

Reputation:

Setting values to nil - swift/parse

I have a UISwitch in my app which I want to register and unregister push notifications. I am currently using parse and I want the app to update to devicetoken in the usertable on the server as well. I'm using this code but it crashes when I flip the switch. "Can't use nil for keys or values on PFObject."

So how would I deal with dropping the value from the current installation and usertable if I can't set to nil.

 UIApplication.sharedApplication().unregisterForRemoteNotifications()
 switchValue.setOn(false, animated: true)
 installation.deviceToken = nil
 user["devicetoken"] = nil
 user.saveInBackground()

Upvotes: 3

Views: 1235

Answers (2)

kviksilver
kviksilver

Reputation: 3854

You should use removeObjectForKeyon PFObject. that way when you get back same data from parse, you will get nil, not an empty string

Upvotes: 4

Dave Wood
Dave Wood

Reputation: 13333

Just use user["devicetoken"] = "", and be sure to check for a blank string before trying to use the token to send a notification.

Upvotes: -1

Related Questions