目前我有一个名为 Place 的类定义如下:
class Place {
let name: String
let address: String
let coordinate: CLLocationCoordinate2D
let type: String
var photoReference: String?
var photo: UIImage?
/* functions etc */
}
在我的数据模型中,我有一个名为 FoundPlaces 的实体。它有一个属性 place
,类型为“transformable”。
我快要发疯了,试图找到存储此对象的 Swift 解决方案。开头的数据模型是不是错了?
任何指导表示赞赏。谢谢!
最佳答案
transformable属性中存储的对象需要实现NSCoding
协议(protocol)(init(coder:)
和encodeWithCoder:
)。
最简单的方法是让 Place
类继承自 NSObject
并实现上面的方法。
关于swift - 核心数据 : How do I store a custom object as a transformable attribute?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30473642/