A swifter Core Data stack
This library aims to do the following:
- Encode Core Data best practices, so you don't have to think "is this correct?" or "is this the right way to do this?"
- Provide better interoperability with Swift
- Harness Swift features and enforce Swift paradigms
- Bring functional paradigms to Core Data
- Make Core Data more Swifty
- Simplify the processes of standing up the Core Data stack
- Aid in testing your Core Data models
- Reduce the boilerplate involved with Core Data
Further reading on Core Data:
- Xcode 12.0+
- Swift 5.3+
- iOS 11.0+
- macOS 10.12+
- tvOS 11.0+
- watchOS 4.0+
pod 'JSQCoreDataKit', '~> 9.0.0' # develop branch pod 'JSQCoreDataKit', :git => 'https://github.com/jessesquires/JSQCoreDataKit.git', :branch => 'develop'
JSQCoreDataKit to the
dependencies value of your
dependencies: [ .package(url: "https://github.com/jessesquires/JSQCoreDataKit.git", from: "9.0.0") ]
Alternatively, you can add the package directly via Xcode.
Interested in making contributions to this project? Please review the guides below.
Created and maintained by @jesse_squires.
Released under the MIT License. See
LICENSE for details.
Copyright © 2015-present Jesse Squires.
You may find interesting
9.0.3 - 2020-09-25T21:55:42
This release closes the 9.0.3 milestone.
- Upgraded to Xcode 12 and Swift 5.3
9.0.2 - 2020-05-09T00:07:44
This release closes the 9.0.2 milestone.
- Support for Swift Package Manager
- Upgraded to Swift 5.2
- Upgraded to Xcode 11.4
- Upgraded to SwiftLint 0.39.2
9.0.1 - 2019-09-24T20:41:28
This release closes the 9.0.1 milestone.
- Carthage support (#92, #138, @kevnm67)
9.0.0 - 2019-09-22T01:08:55
This release closes the 9.0.0 milestone.
func save(wait:, completion:). Replaced with two new extension methods,
SaveResulttype in favor of Swift's new generic
StackResulttype in favor of Swift's new generic
typealias SaveResult = Result<NSManagedObjectContext, Error>(Replaces the former
typealias StackResult = Result<CoreDataStack, Error>(Replaces the former
- Upgraded to Swift 5.1
- Update to Xcode 11
- Update SwiftLint to 0.35.0, add new rules
8.0.0 - 2018-11-07T18:25:06
This release closes the 8.0.0 milestone.
- iOS 11.0 minimum now required
- tvOS 11.0 minimum now required
- macOS 10.12 minimum now required
- watchOS 4.0 minimum now required
- Upgraded to Swift 4.2 (#125)
- Update to Xcode 10.1
- Update SwiftLint to 0.27.0
PersistentStoreOptionstypealias is now
Make APIs more "swifty" (#120)
- Nest top-level function
saveContext()top-level function to extension method on
- Nest top-level function
Equatableauto-synthesis where possible
7.0.0 - 2017-09-27T03:36:35
- Converted to Swift 4.0
- iOS 9.0 minimum now required
- tvOS 10.0 minimum now required
- watchOS 3.0 minimum now required
- macOS 10.11 minimum now required
6.0.3 - 2017-04-04T15:26:03
- Fixed some warnings from Swift 3.1 / Xcode 8.3
6.0.2 - 2017-01-03T17:05:57
This release closes the 6.0.2 milestone.
- Fixed an issue where model migrations would fail. (#106, #109. Thanks @yasserislam, @marius-serban!)
6.0.1 - 2016-10-27T14:48:07
This release closes the 6.0.1 milestone.
- Fixed an issue with
carthagefailing. (#100, #101, #102) Thanks @darkhonor and @tonyarnold!
6.0.0 - 2016-09-30T22:51:45
This release closes the 6.0.0 milestone.
Swift 3.0 now required.
- Migrated to Swift 3.0
entity(name: String, context: NSManagedObjectContext) -> NSEntityDescription
FetchRequest<T: NSManagedObject>(new Swift overlays now provide generic
- Remove the
NSManagedObjectContext(new Swift overlays now provide these)
- There's a new protocol,
CoreDataEntityProtocol, which provides a better API for creating entity descriptions and inserting managed objects (#87). It also provides some helpful extensions. Conform to the new
CoreDataEntityProtocolto take advantage of this. This replaces the (removed) top-level function
entity(name:, context:) -> NSEntityDescription
5.0.0 - 2016-09-15T21:20:47
This release closes the 5.0.0 milestone.
Swift 2.3 now required.
4.0.2 - 2016-06-06T06:20:32
This release closes the 4.0.2 milestone.
- Fixed an issue where sqlite temporary files would not be cleaned up when removing the store (#85). Thanks @deemadden!
4.0.1 - 2016-06-02T01:23:39
This release closes the 4.0.1 milestone.
- Fixed a multithreading concurrency violation while merging (#83). Thanks @saurabytes!
4.0.0 - 2016-05-08T21:08:48
This release closes the 4.0.0 milestone.
This release includes a significant change to
CoreDataStack, which no longer uses child contexts. The
backgroundContext are now both connected to the persistent store coordinator. See #60 for the background and rationale behind this change. In short, child contexts are considered bad practice for this kind of stack setup and should really only be used for "throw away" work.
While this is technically a breaking change, it likely will not affect most clients. The behavior should remain largely unchanged — data is still kept in-sync between the 2 contexts. So unless you were specifically relying on this parent-child nesting behavior, you should be fine. 👍
Huge thanks to @Liquidsoul for closing most of the issues for this release and to @wiedem for contributing significantly as well! 🎉
Breaking changes ⚠️
backgroundContextare now both connected to the persistent store coordinator (#60)
- When creating a child context, the
concurrencyTypedetermines which context is the parent (#73)
CoreDataStackFactoryhas been simplified. There is now a single
In alignment with the latest Swift API guidelines, the library now prefers methods/extensions over free functions.
resetStack()top-level function is now a method on
deleteObjects()top-level function is now an extension method on
fetch()top-level function is now an extension method on
migrate()top-level function is now an extension method
All docs have been updated. As usual, check these out for more details on the changes described above.
There have been other general refinements and additional unit tests have been added. Test coverage is 94% 😎
3.0.0 - 2016-04-04T05:48:52
This release closes the 3.0.0 milestone.
The goals of this release are primarily to adopt Swift 2.2 and refine the API to make it more Swifty, as the definition of Swifty has evolved.
Breaking changes :warning:
There are many breaking changes in this release, however — with the exception of Swift 2.2 — they are all merely name changes that aim to reduce verbosity.
- Migrated to Swift 2.2. (#67) Swift 2.2 and above is now required.
- Renamed all
enumcases to be lowercase, in line with latest Swift API guidelines
StackResultClosuretypealias has been removed
2.2.1 - 2016-04-02T19:59:50
This release closes the 2.2.1 milestone.
- Fixed multithreading violation while saving context (#63, #59, #65). Thanks @saurabytes and @markkrenek!
tvOS, the default SQLite directory now defaults to
.DocumentDirectory(#61, #62). Thanks @cgoldsby !
2.2.0 - 2015-12-28T19:35:03
This release closes the 2.2.0 milestone.
resetStack() top-level function. See the updated docs for details. Thanks @marius-serban! :tada:
CoreDataStackFactory.CompletionHandler was moved from the factory's scope to the module's scope and renamed to
StackResultClosure. This is technically a breaking change, but it is highly unlikely that anyone was referring to this closure directly. If so, simply rename to the correct type.
2.1.0: All the platforms! - 2015-12-03T02:53:40
JSQCoreDataKit now "officially" supports all Apple platforms: iOS, OSX, tvOS, watchOS. :tada:
:trophy: 2.1.0 milestone
2.0.0 - 2015-10-17T06:10:38
JSQCoreDataKit 2.0 is here! :tada:
- Swift 2.0
- You must now initialize
CoreDataStackFactory. This will init the stack on a background queue and return to your completion handler on the main queue when finished. This is necessary since adding a persistent store can take an unknown amount of time.
- Rethinking and rewriting of
CoreDataStack. It now has a
- Saving a context now returns a
CoreDataSaveResultto the completion handler, instead of
CoreDataStackFactoryfor async stack initialization, as mentioned above. It also support synchronous init if you need it, but this is only recommended for testing. Returns a
- All types now conform to
Find the complete list of closed issues here. :bug:
All documentation has been updated. :scroll:
The example app is actually an example app now, check it out! It's a pretty substantial demo.
Release 1.1.0 - 2015-04-26T05:04:55
Release 1.0.0 - 2015-03-22T20:15:15
README and documentation.