本文介绍了在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:
// 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进行子类化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!