Subclassing PFObject in Swift

前端 未结 5 2296
南方客
南方客 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:51

    I ran into the same issue, though I should note that your class definition should look more like this:

    class Armor : PFObject, PFSubclassing {
        var displayName: String
    
        class func parseClassName() -> String! {
            return "Armor"
        }
    }
    
    var armor = Armor()
    armor.displayName = "Iron Clad"
    

    I tried a few different things without success. It doesn't look like the Parse SDK supports this yet, keep in mind that the current release of the Parse iOS SDK predates the swift announcement. Sounds like they're working on better swift support for an upcoming release though.

    Instead, you can still create PFObject subclasses (as you did) and access data with .getObjectForKey("displayName"), or write your own class methods to access this data. The biggest missing piece is really just some convenience methods that the SDK usually creates for you.

提交回复
热议问题