parse-platformparse-ios-sdk

Remove value for a key on a PFObject


I am trying to update an object based on an edit object form that I provided to the user. Whenever the value for a field is set to "" It gives me an error Can't use nil for keys or values on PFObject. Use NSNull for values. I have tried a couple of other things like self.Asset!["Manufacturer"] = nil, self.Asset!["Manufacturer"] = "" and self.Asset!.remove(forKey: "Manufacturer") All of these gave me the same error. Asset is a PFObject and Manufacturer is a key for that object. Below is the sample code for a field

        if(ManufacturerLabel.text != ""){
            self.Asset!["Manufacturer"] = ManufacturerLabel.text
        }else{
            self.Asset!.remove(forKey: "Manufacturer")
            //self.Asset!["Manufacturer"] = nil
        }

P.S. Please do not downvote it as I already checked the Parse Documents and other similar questions and nothing seems to work here.


Solution

  • As the error says, you need to use NSNull. Try:

    self.Asset!["Manufacturer"] = NSNull()