DataModelKit 是一个简单轻量的框架,用于解析和读取 *.xcdatamodel 文件。 它提供了一个 API 来浏览和探索 DataModel。
它被用于 DataModelGen 工具中。 (即将推出)
import DataModelKit
static let path = "Project/Ressources/Sample.xcdatamodel"
let model = try? DataModel(with: DataModelKitTests.pathTest)
print(model.entities)
EasyRealm 可以通过 CocoaPods, Carthage 和 SPM 获取。
use_frameworks!
pod "DataModelKit"
github 'PoissonBallon/DataModelKit'
dependencies: [
.package(url: "https://github.com/PoissonBallon/DataModelKit.git", .upToNextMinor(from:"1.0.0"))
],
DataModelKit 提供了一些带有属性的结构体来利用你的 DataModel。
它是你的 DataModel 的根对象。
public struct DataModel {
public let path: Struct /// Path of the original file.xcdatamodel
public let entities: [Entity] /// Parsed model's entities
public let documentVersion: String /// Version of file.xcdatamodel
public let systemVersion: String /// System version of file.xcdatamodel
public let minimumToolsVersion: String /// Minimum tools version of file.xcdatamodel
public let lastSavedToolsVersion: String /// Last saved tools version of file.xcdatamodel
}
public struct Entity {
public let name: String ///
public let userInfos: [UserInfo]
public let attributes: [Attribute]
public let relationships: [Relationship]
}
public struct Relationship {
public let name: String
public let destination: String
public let inverse: String?
public let userInfo: [UserInfo]
public let toMany: Bool
public let toOne: Bool
public let optional: Bool
public let syncable: Bool
public let ordered: Bool
}
public struct Attribute {
public let name: String
public let optional: Bool
public let indexed: Bool
public let defaultValue: String?
public let type: String
public let userInfos: [UserInfo]
}
DataModelKit 基于 MIT 许可发布。 查看 LICENSE 文件获取更多信息。