From 95c87aa689b043f04d8c1254a9db0f138f6cb151 Mon Sep 17 00:00:00 2001 From: John Estropia Date: Thu, 19 Mar 2015 23:40:42 +0900 Subject: [PATCH 1/3] Create README.md --- README.md | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..884df14 --- /dev/null +++ b/README.md @@ -0,0 +1,59 @@ +# HardcoreData +[![Version](https://img.shields.io/cocoapods/v/HardcoreData.svg?style=flat)](http://cocoadocs.org/docsets/HardcoreData) +[![Platform](https://img.shields.io/cocoapods/p/HardcoreData.svg?style=flat)](http://cocoadocs.org/docsets/HardcoreData) +[![License](https://img.shields.io/cocoapods/l/HardcoreData.svg?style=flat)](http://cocoadocs.org/docsets/HardcoreData) + +Simple, elegant, and smart Core Data programming with Swift + + +## Features +- Supports multiple persistent stores per *data stack*, just the way .xcdatamodeld files are supposed to. HardcoreData will also manage one *data stack* by default, but you can create and manage as many as you need. (see "Setting up") +- Ability to plug-in your own logging framework (or your favorite 3rd-party logger). (see "Logging and error handling") +- Makes it hard to fall into common concurrency mistakes. All Core Data tasks are encapsulated into safer, higher-level abstractions without sacrificing flexibility and customizability. (see "Saving and processing transactions") +- Provides convenient API for common use cases. (see "Fetching and querying") +- Pleasant API designed around Swift’s code elegance and type safety. (see "TL;DR sample codes") + + + +#### TL;DR sample codes +```swift +``` + + + +## Architecture +For maximum safety and performance, HardcoreData will enforce coding patterns and practices it was designed for. (Don't worry, it's not as scary as it sounds.) But it is advisable to understand the "magic" of HardcoreData before you use it in your apps. + +If you are already familiar with the inner workings of CoreData, here is a mapping of `HardcoreData` abstractions: + +| *Core Data* | *HardcoreData* | +| --- | --- | +| `NSManagedObjectModel` / `NSPersistentStoreCoordinator`
(.xcdatamodeld file) | `DataStack` | +| `NSPersistentStore`
("Configuration"s in the .xcdatamodeld file) | `DataStack` configuration
(multiple sqlite / in-memory stores per stack) | +| `NSManagedObjectContext` | `BaseDataTransaction` subclasses
(`SynchronousDataTransaction`, `AsynchronousDataTransaction`, `DetachedDataTransaction`) | + +RestKit and MagicalRecord set up their `NSManagedObjectContext` this way: + +This ensures maximum data integrity between contexts without blocking the main queue. But as Florian Kugler's investigation found out, merging contexts is still by far faster than nesting contexts. HardcoreData's `DataStack` takes the best of both worlds by treating the main `NSManagedObjectContext` as a read-only context, and only allows changes to be made within *transactions*: + +This allows for a butter-smooth main thread, while still benefitting from the safety of nested contexts. + + + +## Setting up + + +## Saving and processing transactions + + +## Fetching and querying + + +## Logging and error handling + + +## Observing changes and notifications (currently in the works) + + + + From 8c989bfb484b448db324d22de0f2591b7c5faa34 Mon Sep 17 00:00:00 2001 From: John Estropia Date: Fri, 20 Mar 2015 00:01:17 +0900 Subject: [PATCH 2/3] Update README.md --- README.md | 45 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 884df14..eac34dc 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,6 @@ Simple, elegant, and smart Core Data programming with Swift - ## Features - Supports multiple persistent stores per *data stack*, just the way .xcdatamodeld files are supposed to. HardcoreData will also manage one *data stack* by default, but you can create and manage as many as you need. (see "Setting up") - Ability to plug-in your own logging framework (or your favorite 3rd-party logger). (see "Logging and error handling") @@ -13,10 +12,50 @@ Simple, elegant, and smart Core Data programming with Swift - Provides convenient API for common use cases. (see "Fetching and querying") - Pleasant API designed around Swift’s code elegance and type safety. (see "TL;DR sample codes") - - #### TL;DR sample codes + +Quick-setup: ```swift +HardcoreData.defaultStack.addSQLiteStore("MyStore.sqlite") +``` + +Simple transactions: +```swift +HardcoreData.beginAsynchronous { (transaction) -> Void in + let object = transaction.create(MyEntity) + object.entityID = 1 + object.name = "test entity" + + transaction.commit { (result) -> Void in + switch result { + case .Success(let hasChanges): println("success!") + case .Failure(let error): println(error) + } + } +} +``` + +Easy fetching: +```swift +let objects = HardcoreData.fetchAll(MyEntity) +``` +```swift +let objects = HardcoreData.fetchAll( + MyEntity.self, + Where("entityID", isEqualTo: 1), + SortedBy(.Ascending("entityID"), .Descending("name")), + CustomizeFetch { (fetchRequest) -> Void in + fetchRequest.includesPendingChanges = true + } +) +``` + +Simple queries: +```swift +let count = HardcoreData.queryValue( + MyEntity.self, + Select(.Count("entityID")) +) ``` From 7377d5adc4cfacb16af6a5e7e11c285c762b415f Mon Sep 17 00:00:00 2001 From: John Estropia Date: Fri, 20 Mar 2015 00:46:18 +0900 Subject: [PATCH 3/3] Update README.md --- README.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index eac34dc..489dc83 100644 --- a/README.md +++ b/README.md @@ -67,15 +67,17 @@ If you are already familiar with the inner workings of CoreData, here is a mappi | *Core Data* | *HardcoreData* | | --- | --- | -| `NSManagedObjectModel` / `NSPersistentStoreCoordinator`
(.xcdatamodeld file) | `DataStack` | -| `NSPersistentStore`
("Configuration"s in the .xcdatamodeld file) | `DataStack` configuration
(multiple sqlite / in-memory stores per stack) | -| `NSManagedObjectContext` | `BaseDataTransaction` subclasses
(`SynchronousDataTransaction`, `AsynchronousDataTransaction`, `DetachedDataTransaction`) | +| `NSManagedObjectModel` / `NSPersistentStoreCoordinator`
(.xcdatamodeld file) | `DataStack` | +| `NSPersistentStore`
("Configuration"s in the .xcdatamodeld file) | `DataStack` configuration
(multiple sqlite / in-memory stores per stack) | +| `NSManagedObjectContext` | `BaseDataTransaction` subclasses
(`SynchronousDataTransaction`, `AsynchronousDataTransaction`, `DetachedDataTransaction`) | -RestKit and MagicalRecord set up their `NSManagedObjectContext` this way: +RestKit and MagicalRecord set up their `NSManagedObjectContext`s this way: +nested contexts -This ensures maximum data integrity between contexts without blocking the main queue. But as Florian Kugler's investigation found out, merging contexts is still by far faster than nesting contexts. HardcoreData's `DataStack` takes the best of both worlds by treating the main `NSManagedObjectContext` as a read-only context, and only allows changes to be made within *transactions*: +This ensures maximum data integrity between contexts without blocking the main queue. But as Florian Kugler's investigation found out, merging contexts is still by far faster than saving nested contexts. HardcoreData's `DataStack` takes the best of both worlds by treating the main `NSManagedObjectContext` as a read-only context, and only allows changes to be made within *transactions*: +nested contexts and merge hybrid -This allows for a butter-smooth main thread, while still benefitting from the safety of nested contexts. +This allows for a butter-smooth main thread, while still taking advantage of safe nested contexts.