我有一个从 Xcode 为我的尺寸模型生成的 Size 类,如下:
@objc(Size)
public class Size: NSManagedObject {
override init(entity: NSEntityDescription, insertInto context: NSManagedObjectContext?) {
super.init(entity: entity, insertInto: context)
}
}
extension Size {
@nonobjc public class func fetchRequest() -> NSFetchRequest<Size> {
return NSFetchRequest<Size>(entityName: "Size")
}
@NSManaged public var id: Int16
@NSManaged public var name: String?
var quantity: Int
func setQuantity() {}
}
Quantity var 和 setQuantity 方法无法从我的 ViewController 访问,尽管我在声明之前将其公开,有什么建议吗?
最佳答案
您将收到编译器错误:扩展不得包含存储的属性
您应该更新它并将变量放入您的类而不是扩展中。
public class Size: NSManagedObject {
var quantity: Int
// Same for other variables.
// Your existing code goes here.
}
尝试并分享您的结果。
关于ios - 向 NSManagedObject 类添加函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53476307/