gpt4 book ai didi

swift - 核心数据 : How do I store a custom object as a transformable attribute?

转载 作者:可可西里 更新时间:2023-10-31 23:44:49 25 4
gpt4 key购买 nike

目前我有一个名为 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com