在 Swift 中继承 PFObject [英] Subclassing PFObject in Swift

查看:16
本文介绍了在 Swift 中继承 PFObject的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用于在 PFObject 子类上添加属性和方法的 Parse 文档方便地跳过了示例代码中的 Swift 语法,仅列出了 Objective-C 语法:

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:

https://parse.com/docs/ios_guide#subclasses-properties/iOS

// Armor.h
@interface Armor : PFObject<PFSubclassing>
+ (NSString *)parseClassName;
@property (retain) NSString *displayName;
@end

// Armor.m
@dynamic displayName;

有没有人想出解决 Swift 缺乏动态合成器的方法,以便使用 PFSubclassing 实现属性和方法?我希望能够执行以下操作:

Has anyone figured out a work around for Swift's lack of dynamic synthesizers in order to implement properties and methods with PFSubclassing? I want to be able to do something like:

class Armor : PFObject, PFSubclassing {
    class func parseClassName() -> String! {
        return "Armor"
    }
}

var armor = Armor()
armor.displayName = "Iron Clad"

推荐答案

我遇到了同样的问题.不得不将@NSManaged 添加到我想要保存的属性中:

I had this same problem. Had to add @NSManaged to the properties I wanted saved:

class Armor : PFObject, PFSubclassing {
    @NSManaged var displayName: String

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

var armor = Armor.object()
armor.displayName = "Iron Clad"

希望能在下次更新中解决这个问题.

Hopefully this is resolved in the next update.

这篇关于在 Swift 中继承 PFObject的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆