Subclassing PFObject in Swift

前端 未结 5 2259
南方客
南方客 2020-12-05 14:49

The Parse documentation for adding properties and methods on PFObject subclasses conveniently skips the Swift syntax in their sample code listing just the Objective-C syntax

5条回答
  •  时光取名叫无心
    2020-12-05 15:45

    Prototypic is correct. As of right now it won't work with the dynamic attribute, but the code sample doesn't include the registerSubclass Parse recommends, so the code should include it like this:

    class Armor : PFObject, PFSubclassing {
        @NSManaged var displayName: String
    
        override class func load() {
            self.registerSubclass()
        }
        class func parseClassName() -> String! {
            return "Armor"
        }
    }
    
    var armor = Armor.object()
    armor.displayName = "Iron Clad"
    

    (Note that "override" is required but missing from the Parse documentation.)

提交回复
热议问题