An easy to use CoreData wrapper in Swift.
DataKit requires Swift 5.0 and Xcode 10.2.
You can use CocoaPods to integrate DataKit with your project.
Simply add the following line to your Podfile
:
pod "AUCoreDataKit"
And run pod update
in your project directory.
Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.
You can install Carthage with Homebrew using the following command:
$ brew update
$ brew install carthage
To integrate NetKit into your Xcode project using Carthage, specify it in your Cartfile
:
github "azizuysal/AUCoreDataKit"
Run carthage update
to build the framework and drag the built DataKit.framework
into your Xcode project.
You can integrate DataKit manually into your project simply by dragging DataKit.framework
onto Linked Frameworks and Libraries section in Xcode.
Optionally configure DataKit if the defaults are not suitable for your use case. DataKit automatically merges and uses CoreData models created in Xcode and uses Application name to name its database file:
DataKit.configure({
var config = DataKit.Configuration()
config.dbUrl = FileManager.default.urls(for: .libraryDirectory, in: .userDomainMask).first!.appendingPathComponent("test.db")
return config
})
You must call this method once to load data stores for CoreData. You can start using DataKit as soon as the data stores are loaded in the callback. If there was an error, the error parameter will contain the details.
DataKit.loadStores { error in
// your code here
}
Afterwards, you can start using convenient methods on your model classes to interact with core data store:
var story = Story.new()
story.title = "DataKit IS Great!"
story.save()
Or use JsonLoadable protocol to load data from a web api:
Story.execute(in: DataKit.newPrivateContext()) { context in
print("Saving story \(id)")
Story.insertOrUpdateOne(storyJson, in: context, idKey: "id", idColumn: "storyId", idType: Int32.self)
}
Refer to the example project for more usage examples.
Please email me if you'd like more examples and/or additional features.
##License
The MIT License (MIT)