DataModelKit

Version Carthage compatible Platform Build Status Swift 4 codecov License

DataModelKit 是一个简单轻量的框架,用于解析和读取 *.xcdatamodel 文件。 它提供了一个 API 来浏览和探索 DataModel

它被用于 DataModelGen 工具中。 (即将推出)

用法

初始化一个 DataModel 对象

import DataModelKit

static let path = "Project/Ressources/Sample.xcdatamodel"
let model = try? DataModel(with: DataModelKitTests.pathTest)

print(model.entities)

安装

EasyRealm 可以通过 CocoaPods, CarthageSPM 获取。

CocoaPods

use_frameworks!

pod "DataModelKit"

Carthage

github 'PoissonBallon/DataModelKit'

SPM

 dependencies: [
    .package(url: "https://github.com/PoissonBallon/DataModelKit.git", .upToNextMinor(from:"1.0.0"))
  ],

API

DataModelKit 提供了一些带有属性的结构体来利用你的 DataModel。

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
}

Entity(实体)

public struct Entity {
  public let name: String ///
  public let userInfos: [UserInfo]
  public let attributes: [Attribute]
  public let relationships: [Relationship]
}

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
}

Attribute(属性)

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 文件获取更多信息。

其他