Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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()

1 Answers

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

like image 175
kviksilver Avatar answered Jun 06 '26 03:06

kviksilver



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!