解析不保存字段

时间:2016-02-28 04:23:47

标签: ios swift object parse-platform

我正在尝试将对象保存到Parse,并且由于某种原因,一个字段拒绝保存。其他一切都保存得很好。但不是这一件。

self.employeeObject.firstName = self.firstName.text!
            self.employeeObject.lastName = self.lastName.text!
            self.employeeObject.messages = self.messagesEnabledSwitch.on
            self.employeeObject.active = true
            self.employeeObject.pinNumber = "\(pinText!.text!)"
            print(self.employeeObject)
            do {
                try self.employeeObject.save()
            } catch {

            }

打印出来:

<Employees: 0x1265cc070, objectId: new, localId: (null)> {
active = 1;
firstName = m;
lastName = d;
messages = 0;
pin = 3434;
}

但是当它保存时,它不会保存引脚号。引脚号在解析时设置为字符串。所以我试图确保它给出的引脚号是这样处理的。字符串(PIN)和“(Pin)”都没有解决我的问题。

我检查了我的模型,它是正确的。我将它用于应用程序的许多其他部分,而不是这个创作。

有什么想法吗?

编辑: 以下是employeeObject来自的Employee模型:

导入基金会 import Parse

class Employee: PFObject, PFSubclassing {

override class func initialize() {
    self.registerSubclass()
}

class func parseClassName() -> String {
    return "Employees"
}

var objectID : String {
    get {return objectForKey("objectId") as! String}
    set { setObject(newValue, forKey: "objectId") }
}

var pinNumber : String? {
    get {return objectForKey("pinNumber") as? String}
    set { setObject(newValue!, forKey: "pin") }
}

var firstName : String {
    get {return objectForKey("firstName") as! String}
    set { setObject(newValue, forKey: "firstName") }
}

var lastName : String {
    get {return objectForKey("lastName") as! String}
    set { setObject(newValue, forKey: "lastName") }
}

var messages : Bool {
    get {return objectForKey("messages") as! Bool}
    set { setObject(newValue, forKey: "messages") }
}

var userPoint : PFUser? {
    get {return objectForKey("userPointer") as? PFUser}
    set { setObject(newValue!, forKey: "userPointer") }
}

var roleType : Role? {
    get {return objectForKey("roleType") as? Role}
    set {setObject(newValue!, forKey: "roleType") }
}

var active : Bool {
    get { return objectForKey("active") as! Bool }
    set { setObject(newValue, forKey: "active") }
}
}

1 个答案:

答案 0 :(得分:0)

此代码不正确:

var pinNumber : String? {
    get {return objectForKey("pinNumber") as? String}
    set { setObject(newValue!, forKey: "pin") }
}

因为您设置了pin但获得了pinNumber所以您将始终获得默认值,因为它从未设置过。