fixed demo app

This commit is contained in:
John Rommel Estropia
2015-06-04 00:40:19 +09:00
parent 6ed6159eec
commit 49b27f696f
7 changed files with 255 additions and 250 deletions

View File

@@ -145,14 +145,15 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
/**
Deletes the specified `NSManagedObject`'s.
:param: object the `NSManagedObject` type to be deleted
:param: objects other `NSManagedObject`'s type to be deleted
:param: object1 the `NSManagedObject` type to be deleted
:param: object2 another `NSManagedObject` type to be deleted
:param: objects other `NSManagedObject`s type to be deleted
*/
public override func delete(object: NSManagedObject?, _ objects: NSManagedObject?...) {
public override func delete(object1: NSManagedObject?, _ object2: NSManagedObject?, _ objects: NSManagedObject?...) {
CoreStore.assert(!self.isCommitted, "Attempted to delete an entities from an already committed \(typeName(self)).")
super.delete([object] + objects)
super.delete([object1, object2] + objects)
}
/**

View File

@@ -222,12 +222,13 @@ public /*abstract*/ class BaseDataTransaction {
/**
Deletes the specified `NSManagedObject`'s.
:param: object the `NSManagedObject` type to be deleted
:param: objects other `NSManagedObject`'s type to be deleted
:param: object1 the `NSManagedObject` type to be deleted
:param: object2 another `NSManagedObject` type to be deleted
:param: objects other `NSManagedObject`s type to be deleted
*/
public func delete(object: NSManagedObject?, _ objects: NSManagedObject?...) {
public func delete(object1: NSManagedObject?, _ object2: NSManagedObject?, _ objects: NSManagedObject?...) {
self.delete([object] + objects)
self.delete([object1, object2] + objects)
}
/**

View File

@@ -124,14 +124,15 @@ public final class SynchronousDataTransaction: BaseDataTransaction {
/**
Deletes the specified `NSManagedObject`'s.
:param: object the `NSManagedObject` type to be deleted
:param: objects other `NSManagedObject`'s type to be deleted
:param: object1 the `NSManagedObject` type to be deleted
:param: object2 another `NSManagedObject` type to be deleted
:param: objects other `NSManagedObject`s type to be deleted
*/
public override func delete(object: NSManagedObject?, _ objects: NSManagedObject?...) {
public override func delete(object1: NSManagedObject?, _ object2: NSManagedObject?, _ objects: NSManagedObject?...) {
CoreStore.assert(!self.isCommitted, "Attempted to delete an entities from an already committed \(typeName(self)).")
super.delete([object] + objects)
super.delete([object1, object2] + objects)
}
/**

View File

@@ -22,7 +22,7 @@
<key>4B60F1BCB491FF717C56441AE7783C74F417BE48</key>
<string>../../..</string>
<key>8B2E522D57154DFA93A06982C36315ECBEA4FA97</key>
<string>../../../Libraries/GCDKit/</string>
<string>../../../Libraries/GCDKit</string>
</dict>
<key>IDESourceControlProjectURL</key>
<string>github.com:JohnEstropia/CoreStore.git</string>

View File

@@ -123,7 +123,7 @@ class ObjectObserverDemoViewController: UIViewController, ManagedObjectObserver
let hue = self.hueSlider?.value ?? 0
CoreStore.beginAsynchronous { [weak self] (transaction) -> Void in
if let palette = transaction.fetch(self?.objectController?.object) {
if let palette = transaction.edit(self?.objectController?.object) {
palette.hue = Int32(hue)
transaction.commit()
@@ -136,7 +136,7 @@ class ObjectObserverDemoViewController: UIViewController, ManagedObjectObserver
let saturation = self.saturationSlider?.value ?? 0
CoreStore.beginAsynchronous { [weak self] (transaction) -> Void in
if let palette = transaction.fetch(self?.objectController?.object) {
if let palette = transaction.edit(self?.objectController?.object) {
palette.saturation = saturation
transaction.commit()
@@ -149,7 +149,7 @@ class ObjectObserverDemoViewController: UIViewController, ManagedObjectObserver
let brightness = self.brightnessSlider?.value ?? 0
CoreStore.beginAsynchronous { [weak self] (transaction) -> Void in
if let palette = transaction.fetch(self?.objectController?.object) {
if let palette = transaction.edit(self?.objectController?.object) {
palette.brightness = brightness
transaction.commit()

View File

@@ -161,7 +161,7 @@ class TransactionsDemoViewController: UIViewController, MKMapViewDelegate, Manag
CoreStore.beginAsynchronous { (transaction) -> Void in
let place = transaction.fetch(Static.placeController.object)
let place = transaction.edit(Static.placeController.object)
place?.coordinate = mapView.convertPoint(
gesture.locationInView(mapView),
toCoordinateFromView: mapView
@@ -175,7 +175,7 @@ class TransactionsDemoViewController: UIViewController, MKMapViewDelegate, Manag
CoreStore.beginSynchronous { (transaction) -> Void in
let place = transaction.fetch(Static.placeController.object)
let place = transaction.edit(Static.placeController.object)
place?.setInitialValues()
transaction.commit()
}
@@ -195,7 +195,7 @@ class TransactionsDemoViewController: UIViewController, MKMapViewDelegate, Manag
if let strongSelf = self, let placemark = (placemarks as? [CLPlacemark])?.first {
let place = transaction.fetch(Static.placeController.object)
let place = transaction.edit(Static.placeController.object)
place?.title = placemark.name
place?.subtitle = ABCreateStringWithAddressDictionary(placemark.addressDictionary, true)
transaction.commit { (_) -> Void in }

View File

@@ -10,10 +10,10 @@ 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. CoreStore will also manage one *data stack* by default, but you can create and manage as many as you need.
- 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.
- 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 Swifts code elegance and type safety.
@@ -194,7 +194,7 @@ CoreStore.beginAsynchronous { (transaction) -> Void in
transaction.commit()
}
```
`transaction`'s created from `beginAsynchronous(...)` are instances of `AsynchronousDataTransaction`.
Transactions created from `beginAsynchronous(...)` are instances of `AsynchronousDataTransaction`.
**Synchronous transactions** are created from `beginSynchronous(...)`. While the syntax is similar to its asynchronous counterpart, `beginSynchronous(...)` waits for its transaction block to complete before returning:
```swift
@@ -252,7 +252,7 @@ Note that if you do explicitly specify the configuration name, CoreStore will on
### Updating objects
After creating an object from the transaction, you can simply update it's properties as normal:
After creating an object from the transaction, you can simply update its properties as normal:
```swift
CoreStore.beginAsynchronous { (transaction) -> Void in
let person = transaction.create(Into(MyPersonEntity))
@@ -339,7 +339,7 @@ Before we dive in, be aware that CoreStore distinguishes between *fetching* and
- unsaved objects should be included in the search (though fetches can be configured to exclude unsaved ones)
- A *query* pulls data straight from the persistent store. This means faster searches when computing aggregates such as *count*, *min*, *max*, etc. Use queries when:
- you need to compute aggregate functions (see below for a list of supported functions)
- results can be raw values like `NSString`'s, `NSNumber`'s, `Int`'s, `NSDate`'s, an `NSDictionary` of key-values, etc.
- results can be raw values like `NSString`s, `NSNumber`s, `Int`s, `NSDate`s, an `NSDictionary` of key-values, etc.
- only specific attribute keys need to be included in the results
- unsaved objects should be ignored
@@ -367,8 +367,8 @@ There are currently 5 fetch methods you can call from `CoreStore`, from a `DataS
- `fetchAll(_:_:)` - returns an array of all objects that match the criteria.
- `fetchOne(_:_:)` - returns the first object that match the criteria.
- `fetchCount(_:_:)` - returns the number of objects that match the criteria.
- `fetchObjectIDs(_:_:)`` - returns an array of `NSManagedObjectID`'s for all objects that match the criteria.
- `fetchObjectID(_:_:)` - returns the `NSManagedObjectID`'s for the first objects that match the criteria.
- `fetchObjectIDs(_:_:)`` - returns an array of `NSManagedObjectID`s for all objects that match the criteria.
- `fetchObjectID(_:_:)` - returns the `NSManagedObjectID`s for the first objects that match the criteria.
Each method's purpose is straightforward, but we need to understand how to set the clauses for the fetch.
@@ -413,7 +413,7 @@ var mostValuablePeople = CoreStore.fetchAll(
```
As seen above, `OrderBy` accepts a list of `SortKey` enumeration values, which can be either `.Ascending` or `.Descending`. The associated value for the `SortKey` enumeration is the attribute key string.
You can use the `+` and `+=` operator to append `OrderBy`'s together. This is useful when sorting conditionally:
You can use the `+` and `+=` operator to append `OrderBy`s together. This is useful when sorting conditionally:
```swift
var orderBy = OrderBy(.Descending("rating"))
if sortFromYoungest {
@@ -592,7 +592,7 @@ this returns dictionaries that shows the count for each `"age"`:
```
## <a id="logging"></a>Logging and error handling
One unfortunate thing when using some third-party libraries is that they usually pollute the console with their own logging mechanisms. CoreStore provides it's own default logging class, but you can plug-in your own favorite logger by implementing the `CoreStoreLogger` protocol.
One unfortunate thing when using some third-party libraries is that they usually pollute the console with their own logging mechanisms. CoreStore provides its own default logging class, but you can plug-in your own favorite logger by implementing the `CoreStoreLogger` protocol.
```swift
final class MyLogger: CoreStoreLogger {
func log(#level: LogLevel, message: String, fileName: StaticString, lineNumber: Int, functionName: StaticString) {
@@ -646,7 +646,7 @@ let person: MyPersonEntity = // ...
self.objectController = CoreStore.observeObject(person)
self.objectController.addObserver(self)
```
The controller will then notify our observer whenever the object's attributes change. You can add multiple `ManagedObjectObserver`'s to a single `ManagedObjectController` without any problem. This means you can just share around the `ManagedObjectController` instance to different screens without problem.
The controller will then notify our observer whenever the object's attributes change. You can add multiple `ManagedObjectObserver`s to a single `ManagedObjectController` without any problem. This means you can just share around the `ManagedObjectController` instance to different screens without problem.
You can get `ManagedObjectController`'s object through its `object` property. If the object is deleted, the `object` property will become `nil` to prevent further access.
@@ -690,7 +690,7 @@ self.listController = CoreStore.observeObjectList(
)
self.listController.addObserver(self)
```
Similar to `ManagedObjectController`, a `ManagedObjectListController` can also have multiple `ManagedObjectListChangeObserver`'s registered to a single `ManagedObjectListController`.
Similar to `ManagedObjectController`, a `ManagedObjectListController` can also have multiple `ManagedObjectListChangeObserver`s registered to a single `ManagedObjectListController`.
If you have noticed, the `observeObjectList(...)` method accepts `Where`, `OrderBy`, and `Tweak` clauses exactly like a fetch. As the list maintained by `ManagedObjectListController` needs to have a deterministic order, at least the `From` and `OrderBy` clauses are required.
@@ -766,8 +766,10 @@ Drag and drop **CoreStore.xcodeproj** to your project.
Add all *.swift* files to your project.
# Contributions
While CoreStore's design is pretty solid and the unit test and demo app work well, CoreStore is pretty much still in it's early stage. With more exposure to production code usage and criticisms from the developer community, CoreStore hopes to mature as well.
While CoreStore's design is pretty solid and the unit test and demo app work well, CoreStore is pretty much still in its early stage. With more exposure to production code usage and criticisms from the developer community, CoreStore hopes to mature as well.
Please feel free to report any issues, suggestions, or criticisms!
日本語で連絡していただいても構いません!
## License