Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Parse.com booleans in subclasses

I have subclassed PFUser and added a property isManager

class User : PFUser, PFSubclassing {
 @NSManaged var isManager: Bool
 override class func load() {
  self.registerSubclass()
 }   
}

I tried

user.isManager = false

but get the run time error

[Foo.User setIsManager:]: unrecognized selector sent to instance 0x145bf550

I also tried using NSNumber because of core data

user.isManager = NSNumber(bool: false)

but get the compile time error

NSNumber is not convertible to bool
like image 857
grabury Avatar asked Dec 26 '22 00:12

grabury


1 Answers

I've actually found it to be much simpler to implement "get" and "set".

class User: PFUser, PFSubclassing {
    var isManager: Bool {
        get { return self["isManager"] as! Bool }
        set { self["isManager"] = newValue }
    }
    ...
}
like image 126
Zooce Avatar answered Feb 05 '23 06:02

Zooce