[英]Map core data row from one table (entity) to an array of [CLLocation]?
在我的ios应用程序中,我使用的是Core数据,我需要在表格中保存一个“区域”数组,我将从JSON中获取。
“Region”对象的模型非常简单:
class Region : NSObject, NSCoding {
...
//MARK: -
//MARK: - Properties
fileprivate var id: String
fileprivate var name: String
fileprivate var boundaryPoints: [CLLocation]
fileprivate var midCoordinate: CLLocationCoordinate2D {
return getPolygonFromBoundaryPoints().coordinate
}
init(id: String, name: String, boundaryPoints: [CLLocation]) {
self.id = id
self.name = name
self.boundaryPoints = boundaryPoints
super.init()
}
//MARK: -
//MARK: - NSCoding
...
//MARK: -
//MARK: - Getters and Setters
...
}
问题是我需要将其保存在一个表中,其中记录将是这样的:
地区表:
在存储有关“Region”对象的信息时,将行映射到(lat,lng)点数组(在本例中为[CLLocation])的最佳解决方案是什么? 因为“Region”对象模型包含一个边界点数组。
换句话说,我应该如何使用Core数据将具有数组属性的对象模型保存到sql? (对表的结构和关系感兴趣)
您需要将核心数据中的值存储为Transformable
并使用值转换器。 您可以在此处找到有关详细信息的教程: http : //lextech.com/2013/01/core-data-transformable-attributes/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.