mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-05-27 01:49:21 +02:00
CoreStore wiki
+74
@@ -0,0 +1,74 @@
|
|||||||
|
# CoreStore
|
||||||
|
[](http://cocoadocs.org/docsets/CoreStore)
|
||||||
|
[](http://cocoadocs.org/docsets/CoreStore)
|
||||||
|
[](http://cocoadocs.org/docsets/CoreStore)
|
||||||
|
|
||||||
|
Simple, elegant, and smart Core Data programming with Swift
|
||||||
|
(Swift, iOS 8+)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## Features
|
||||||
|
- Supports multiple persistent stores per *data stack*, just the way .xcdatamodeld files are supposed to. CoreStore will also manage one *data stack* by default, but you can create and manage as many as you need.
|
||||||
|
- Ability to plug-in your own logging framework (or any of your favorite 3rd-party logger)
|
||||||
|
- Gets around a limitation with other Core Data wrappers where the entity name should be the same as the `NSManagedObject` subclass name. CoreStore loads entity-to-class mappings from the .xcdatamodeld file, so you are free to name them independently.
|
||||||
|
- Observe a list of `NSManagedObject`'s using `ManagedObjectListController`, a clean wrapper for `NSFetchedResultsController`. Another controller, `ManagedObjectController`, lets you observe changes for a single object without using KVO. Both controllers can have multiple observers as well, so there is no extra overhead when sharing the same data source for multiple screens.
|
||||||
|
- Makes it hard to fall into common concurrency mistakes. All `NSManagedObjectContext` tasks are encapsulated into safer, higher-level abstractions without sacrificing flexibility and customizability.
|
||||||
|
- Provides convenient API for common use cases.
|
||||||
|
- Clean API designed around Swift’s code elegance and type safety.
|
||||||
|
|
||||||
|
**CoreStore's goal is not to expose shorter, magical syntax, but to provide an API that prioritizes readability, consistency, and safety.**
|
||||||
|
|
||||||
|
#### TL;DR sample codes
|
||||||
|
|
||||||
|
Quick-setup:
|
||||||
|
```swift
|
||||||
|
CoreStore.addSQLiteStore("MyStore.sqlite")
|
||||||
|
```
|
||||||
|
|
||||||
|
Simple transactions:
|
||||||
|
```swift
|
||||||
|
CoreStore.beginAsynchronous { (transaction) -> Void in
|
||||||
|
let object = transaction.create(Into(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 = CoreStore.fetchAll(From(MyEntity))
|
||||||
|
```
|
||||||
|
```swift
|
||||||
|
let objects = CoreStore.fetchAll(
|
||||||
|
From(MyEntity),
|
||||||
|
Where("entityID", isEqualTo: 1),
|
||||||
|
OrderBy(.Ascending("entityID"), .Descending("name")),
|
||||||
|
Tweak { (fetchRequest) -> Void in
|
||||||
|
fetchRequest.includesPendingChanges = true
|
||||||
|
}
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
Simple queries:
|
||||||
|
```swift
|
||||||
|
let count = CoreStore.queryValue(
|
||||||
|
From(MyEntity),
|
||||||
|
Select<Int>(.Count("entityID"))
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Contents
|
||||||
|
- [[Architecture]]
|
||||||
|
- [[Setting up]]
|
||||||
|
- [[Saving and processing transactions]]
|
||||||
|
- [[Fetching and querying]]
|
||||||
|
- [[Logging and error handling]]
|
||||||
|
- [[Observing changes and notifications]]
|
||||||
Reference in New Issue
Block a user