renamed commitAndWait() to overload commit()

This commit is contained in:
John Rommel Estropia
2015-05-09 19:40:08 +09:00
parent a1610534cb
commit 202ec371f2
13 changed files with 131 additions and 60 deletions

View File

@@ -11,6 +11,7 @@
2F03A54019C5C6DA005002A5 /* HardcoreDataTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F03A53F19C5C6DA005002A5 /* HardcoreDataTests.swift */; }; 2F03A54019C5C6DA005002A5 /* HardcoreDataTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F03A53F19C5C6DA005002A5 /* HardcoreDataTests.swift */; };
2F03A54D19C5C872005002A5 /* CoreData.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2F03A54C19C5C872005002A5 /* CoreData.framework */; }; 2F03A54D19C5C872005002A5 /* CoreData.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2F03A54C19C5C872005002A5 /* CoreData.framework */; };
2F291E2719C6D3CF007AF63F /* HardcoreData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F291E2619C6D3CF007AF63F /* HardcoreData.swift */; }; 2F291E2719C6D3CF007AF63F /* HardcoreData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F291E2619C6D3CF007AF63F /* HardcoreData.swift */; };
B503FAE71AFDE20C00F90881 /* NSManagedObject+Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = B503FAE61AFDE20C00F90881 /* NSManagedObject+Convenience.swift */; };
B50DD9DD1ABD34F800D62F2B /* From.swift in Sources */ = {isa = PBXBuildFile; fileRef = B50DD9DC1ABD34F800D62F2B /* From.swift */; }; B50DD9DD1ABD34F800D62F2B /* From.swift in Sources */ = {isa = PBXBuildFile; fileRef = B50DD9DC1ABD34F800D62F2B /* From.swift */; };
B52B68BA1AAB46AD00CE7F48 /* ManagedObjectController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B52B68B91AAB46AD00CE7F48 /* ManagedObjectController.swift */; }; B52B68BA1AAB46AD00CE7F48 /* ManagedObjectController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B52B68B91AAB46AD00CE7F48 /* ManagedObjectController.swift */; };
B52B68BC1AAB46BD00CE7F48 /* ManagedObjectListController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B52B68BB1AAB46BD00CE7F48 /* ManagedObjectListController.swift */; }; B52B68BC1AAB46BD00CE7F48 /* ManagedObjectListController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B52B68BB1AAB46BD00CE7F48 /* ManagedObjectListController.swift */; };
@@ -90,6 +91,7 @@
2F03A53F19C5C6DA005002A5 /* HardcoreDataTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = HardcoreDataTests.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; 2F03A53F19C5C6DA005002A5 /* HardcoreDataTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = HardcoreDataTests.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
2F03A54C19C5C872005002A5 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = System/Library/Frameworks/CoreData.framework; sourceTree = SDKROOT; }; 2F03A54C19C5C872005002A5 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = System/Library/Frameworks/CoreData.framework; sourceTree = SDKROOT; };
2F291E2619C6D3CF007AF63F /* HardcoreData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = HardcoreData.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; 2F291E2619C6D3CF007AF63F /* HardcoreData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = HardcoreData.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
B503FAE61AFDE20C00F90881 /* NSManagedObject+Convenience.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSManagedObject+Convenience.swift"; sourceTree = "<group>"; };
B50DD9DC1ABD34F800D62F2B /* From.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = From.swift; sourceTree = "<group>"; }; B50DD9DC1ABD34F800D62F2B /* From.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = From.swift; sourceTree = "<group>"; };
B52B68B91AAB46AD00CE7F48 /* ManagedObjectController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ManagedObjectController.swift; sourceTree = "<group>"; }; B52B68B91AAB46AD00CE7F48 /* ManagedObjectController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ManagedObjectController.swift; sourceTree = "<group>"; };
B52B68BB1AAB46BD00CE7F48 /* ManagedObjectListController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ManagedObjectListController.swift; sourceTree = "<group>"; }; B52B68BB1AAB46BD00CE7F48 /* ManagedObjectListController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ManagedObjectListController.swift; sourceTree = "<group>"; };
@@ -191,6 +193,7 @@
B5F409E51A8B11B600A228EA /* Logging */, B5F409E51A8B11B600A228EA /* Logging */,
B5E126531A7DCCE400AD8B39 /* Fetching and Querying */, B5E126531A7DCCE400AD8B39 /* Fetching and Querying */,
B52B68B61AAB45FB00CE7F48 /* Observing */, B52B68B61AAB45FB00CE7F48 /* Observing */,
B503FAE31AFDE1E500F90881 /* Convenience Helpers */,
B5D808141A34945A00A44484 /* Internal */, B5D808141A34945A00A44484 /* Internal */,
2F03A53319C5C6DA005002A5 /* Supporting Files */, 2F03A53319C5C6DA005002A5 /* Supporting Files */,
); );
@@ -237,6 +240,14 @@
name = Frameworks; name = Frameworks;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
B503FAE31AFDE1E500F90881 /* Convenience Helpers */ = {
isa = PBXGroup;
children = (
B503FAE61AFDE20C00F90881 /* NSManagedObject+Convenience.swift */,
);
name = "Convenience Helpers";
sourceTree = "<group>";
};
B52B68B61AAB45FB00CE7F48 /* Observing */ = { B52B68B61AAB45FB00CE7F48 /* Observing */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
@@ -523,6 +534,7 @@
B5CFF23E19FD1D1C00D6DFC4 /* NSManagedObjectContext+HardcoreData.swift in Sources */, B5CFF23E19FD1D1C00D6DFC4 /* NSManagedObjectContext+HardcoreData.swift in Sources */,
B54A9F071AA7654400AFEC05 /* DataStack+Querying.swift in Sources */, B54A9F071AA7654400AFEC05 /* DataStack+Querying.swift in Sources */,
B5E126571A7DCE5900AD8B39 /* SortedBy.swift in Sources */, B5E126571A7DCE5900AD8B39 /* SortedBy.swift in Sources */,
B503FAE71AFDE20C00F90881 /* NSManagedObject+Convenience.swift in Sources */,
B54D53071AB3538500D55BA8 /* QueryClause.swift in Sources */, B54D53071AB3538500D55BA8 /* QueryClause.swift in Sources */,
B5F409EF1A8B243D00A228EA /* BaseDataTransaction+Querying.swift in Sources */, B5F409EF1A8B243D00A228EA /* BaseDataTransaction+Querying.swift in Sources */,
2F291E2719C6D3CF007AF63F /* HardcoreData.swift in Sources */, 2F291E2719C6D3CF007AF63F /* HardcoreData.swift in Sources */,

View File

@@ -38,7 +38,7 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
// MARK: Public // MARK: Public
/** /**
Saves the transaction changes asynchronously. This method should not be used after either the commit(_:) or commitAndWait() method was already called once. Saves the transaction changes asynchronously. This method should not be used after the commit() method was already called once.
:param: completion the block executed after the save completes. Success or failure is reported by the SaveResult argument of the block. :param: completion the block executed after the save completes. Success or failure is reported by the SaveResult argument of the block.
*/ */
@@ -59,11 +59,11 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
} }
/** /**
Saves the transaction changes and waits for completion synchronously. This method should not be used after either the commit(_:) or commitAndWait() method was already called once. Saves the transaction changes and waits for completion synchronously. This method should not be used after the commit() method was already called once.
:returns: a SaveResult value indicating success or failure. :returns: a SaveResult value indicating success or failure.
*/ */
public func commitAndWait() { public func commit() {
HardcoreData.assert(self.transactionQueue.isCurrentExecutionContext(), "Attempted to commit a \(typeName(self)) outside its designated queue.") HardcoreData.assert(self.transactionQueue.isCurrentExecutionContext(), "Attempted to commit a \(typeName(self)) outside its designated queue.")
HardcoreData.assert(!self.isCommitted, "Attempted to commit a \(typeName(self)) more than once.") HardcoreData.assert(!self.isCommitted, "Attempted to commit a \(typeName(self)) more than once.")
@@ -73,7 +73,7 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
} }
/** /**
Begins a child transaction synchronously where NSManagedObject creates, updates, and deletes can be made. This method should not be used after either the commit(_:) or commitAndWait() method was already called once. Begins a child transaction synchronously where NSManagedObject creates, updates, and deletes can be made. This method should not be used after he commit() method was already called once.
:param: closure the block where creates, updates, and deletes can be made to the transaction. Transaction blocks are executed serially in a background queue, and all changes are made from a concurrent NSManagedObjectContext. :param: closure the block where creates, updates, and deletes can be made to the transaction. Transaction blocks are executed serially in a background queue, and all changes are made from a concurrent NSManagedObjectContext.
:returns: a SaveResult value indicating success or failure, or nil if the transaction was not comitted synchronously :returns: a SaveResult value indicating success or failure, or nil if the transaction was not comitted synchronously
@@ -93,7 +93,7 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
// MARK: BaseDataTransaction // MARK: BaseDataTransaction
/** /**
Creates a new NSManagedObject with the specified entity type. This method should not be used after either the commit(_:) or commitAndWait() method was already called once. Creates a new NSManagedObject with the specified entity type. This method should not be used after the commit() method was already called once.
:param: entity the NSManagedObject type to be created :param: entity the NSManagedObject type to be created
:returns: a new NSManagedObject instance of the specified entity type. :returns: a new NSManagedObject instance of the specified entity type.
@@ -106,7 +106,7 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
} }
/** /**
Returns an editable proxy of a specified NSManagedObject. This method should not be used after either the commit(_:) or commitAndWait() method was already called once. Returns an editable proxy of a specified NSManagedObject. This method should not be used after the commit() method was already called once.
:param: object the NSManagedObject type to be edited :param: object the NSManagedObject type to be edited
:returns: an editable proxy for the specified NSManagedObject. :returns: an editable proxy for the specified NSManagedObject.
@@ -119,7 +119,7 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
} }
/** /**
Deletes a specified NSManagedObject. This method should not be used after either the commit(_:) or commitAndWait() method was already called once. Deletes a specified NSManagedObject. This method should not be used after the commit() method was already called once.
:param: object the NSManagedObject type to be deleted :param: object the NSManagedObject type to be deleted
*/ */
@@ -131,7 +131,7 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
} }
/** /**
Rolls back the transaction by resetting the NSManagedObjectContext. After calling this method, all NSManagedObjects fetched within the transaction will become invalid. This method should not be used after either the commit(_:) or commitAndWait() method was already called once. Rolls back the transaction by resetting the NSManagedObjectContext. After calling this method, all NSManagedObjects fetched within the transaction will become invalid. This method should not be used after the commit() method was already called once.
*/ */
public override func rollback() { public override func rollback() {

View File

@@ -2,8 +2,25 @@
// From.swift // From.swift
// HardcoreData // HardcoreData
// //
// Created by John Rommel Estropia on 2015/03/21. // Copyright (c) 2015 John Rommel Estropia
// Copyright (c) 2015 John Rommel Estropia. All rights reserved. //
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
// //
import Foundation import Foundation

View File

@@ -0,0 +1,49 @@
//
// NSManagedObject+Convenience.swift
// HardcoreData
//
// Copyright (c) 2015 John Rommel Estropia
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
import Foundation
import CoreData
// MARK: - NSManagedObject
public extension NSManagedObject {
public func accessValueForKVCKey(KVCKey: KeyPath) -> AnyObject? {
self.willAccessValueForKey(KVCKey)
let primitiveValue: AnyObject? = self.primitiveValueForKey(KVCKey)
self.didAccessValueForKey(KVCKey)
return primitiveValue
}
public func setValue(value: AnyObject?, forKVCKey KVCKey: KeyPath) {
self.willChangeValueForKey(KVCKey)
self.setPrimitiveValue(value, forKey: KVCKey)
self.didChangeValueForKey(KVCKey)
}
}

View File

@@ -38,11 +38,11 @@ public final class SynchronousDataTransaction: BaseDataTransaction {
// MARK: Public // MARK: Public
/** /**
Saves the transaction changes and waits for completion synchronously. This method should not be used after the commitAndWait() method was already called once. Saves the transaction changes and waits for completion synchronously. This method should not be used after the commit() method was already called once.
:returns: a SaveResult value indicating success or failure. :returns: a SaveResult value indicating success or failure.
*/ */
public func commitAndWait() { public func commit() {
HardcoreData.assert(self.transactionQueue.isCurrentExecutionContext(), "Attempted to commit a \(typeName(self)) outside its designated queue.") HardcoreData.assert(self.transactionQueue.isCurrentExecutionContext(), "Attempted to commit a \(typeName(self)) outside its designated queue.")
HardcoreData.assert(!self.isCommitted, "Attempted to commit a \(typeName(self)) more than once.") HardcoreData.assert(!self.isCommitted, "Attempted to commit a \(typeName(self)) more than once.")
@@ -52,7 +52,7 @@ public final class SynchronousDataTransaction: BaseDataTransaction {
} }
/** /**
Begins a child transaction synchronously where NSManagedObject creates, updates, and deletes can be made. This method should not be used after the commitAndWait() method was already called once. Begins a child transaction synchronously where NSManagedObject creates, updates, and deletes can be made. This method should not be used after the commit() method was already called once.
:param: closure the block where creates, updates, and deletes can be made to the transaction. Transaction blocks are executed serially in a background queue, and all changes are made from a concurrent NSManagedObjectContext. :param: closure the block where creates, updates, and deletes can be made to the transaction. Transaction blocks are executed serially in a background queue, and all changes are made from a concurrent NSManagedObjectContext.
:returns: a SaveResult value indicating success or failure, or nil if the transaction was not comitted synchronously :returns: a SaveResult value indicating success or failure, or nil if the transaction was not comitted synchronously
@@ -72,7 +72,7 @@ public final class SynchronousDataTransaction: BaseDataTransaction {
// MARK: BaseDataTransaction // MARK: BaseDataTransaction
/** /**
Creates a new NSManagedObject with the specified entity type. This method should not be used after the commitAndWait() method was already called once. Creates a new NSManagedObject with the specified entity type. This method should not be used after the commit() method was already called once.
:param: entity the NSManagedObject type to be created :param: entity the NSManagedObject type to be created
:returns: a new NSManagedObject instance of the specified entity type. :returns: a new NSManagedObject instance of the specified entity type.
@@ -85,7 +85,7 @@ public final class SynchronousDataTransaction: BaseDataTransaction {
} }
/** /**
Returns an editable proxy of a specified NSManagedObject. This method should not be used after the commitAndWait() method was already called once. Returns an editable proxy of a specified NSManagedObject. This method should not be used after the commit() method was already called once.
:param: object the NSManagedObject type to be edited :param: object the NSManagedObject type to be edited
:returns: an editable proxy for the specified NSManagedObject. :returns: an editable proxy for the specified NSManagedObject.
@@ -98,7 +98,7 @@ public final class SynchronousDataTransaction: BaseDataTransaction {
} }
/** /**
Deletes a specified NSManagedObject. This method should not be used after the commitAndWait() method was already called once. Deletes a specified NSManagedObject. This method should not be used after the commit() method was already called once.
:param: object the NSManagedObject type to be deleted :param: object the NSManagedObject type to be deleted
*/ */
@@ -110,7 +110,7 @@ public final class SynchronousDataTransaction: BaseDataTransaction {
} }
/** /**
Rolls back the transaction by resetting the NSManagedObjectContext. After calling this method, all NSManagedObjects fetched within the transaction will become invalid. This method should not be used after the commitAndWait() method was already called once. Rolls back the transaction by resetting the NSManagedObjectContext. After calling this method, all NSManagedObjects fetched within the transaction will become invalid. This method should not be used after the commit() method was already called once.
*/ */
public override func rollback() { public override func rollback() {

View File

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

View File

@@ -21,7 +21,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
HardcoreData.defaultStack.addSQLiteStore() HardcoreData.defaultStack.addSQLiteStore(resetStoreOnMigrationFailure: true)
return true return true
} }
} }

View File

@@ -120,20 +120,20 @@
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/> <color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/> <nil key="highlightedColor"/>
</label> </label>
<slider opaque="NO" contentMode="scaleToFill" misplaced="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" minValue="0.0" maxValue="359" translatesAutoresizingMaskIntoConstraints="NO" id="YQ6-fq-3Wb"> <slider opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" minValue="0.0" maxValue="359" translatesAutoresizingMaskIntoConstraints="NO" id="YQ6-fq-3Wb">
<rect key="frame" x="98" y="149" width="488" height="31"/> <rect key="frame" x="98" y="148" width="488" height="31"/>
<connections> <connections>
<action selector="hueSliderValueDidChange:" destination="dX3-kR-CYC" eventType="valueChanged" id="9Hy-3h-llE"/> <action selector="hueSliderValueDidChange:" destination="dX3-kR-CYC" eventType="valueChanged" id="9Hy-3h-llE"/>
</connections> </connections>
</slider> </slider>
<slider opaque="NO" contentMode="scaleToFill" misplaced="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" value="1" minValue="0.0" maxValue="1" translatesAutoresizingMaskIntoConstraints="NO" id="xXz-78-tAd"> <slider opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" value="1" minValue="0.0" maxValue="1" translatesAutoresizingMaskIntoConstraints="NO" id="xXz-78-tAd">
<rect key="frame" x="98" y="187" width="488" height="31"/> <rect key="frame" x="98" y="186" width="488" height="31"/>
<connections> <connections>
<action selector="saturationSliderValueDidChange:" destination="dX3-kR-CYC" eventType="valueChanged" id="qtU-ua-ZTc"/> <action selector="saturationSliderValueDidChange:" destination="dX3-kR-CYC" eventType="valueChanged" id="qtU-ua-ZTc"/>
</connections> </connections>
</slider> </slider>
<slider opaque="NO" contentMode="scaleToFill" misplaced="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" value="0.5" minValue="0.0" maxValue="1" translatesAutoresizingMaskIntoConstraints="NO" id="hpy-2d-eOP"> <slider opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" value="0.5" minValue="0.0" maxValue="1" translatesAutoresizingMaskIntoConstraints="NO" id="hpy-2d-eOP">
<rect key="frame" x="98" y="225" width="488" height="31"/> <rect key="frame" x="98" y="224" width="488" height="31"/>
<connections> <connections>
<action selector="brightnessSliderValueDidChange:" destination="dX3-kR-CYC" eventType="valueChanged" id="F09-EP-2iD"/> <action selector="brightnessSliderValueDidChange:" destination="dX3-kR-CYC" eventType="valueChanged" id="F09-EP-2iD"/>
</connections> </connections>
@@ -269,7 +269,6 @@
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" id="DAz-BE-6Ca"> <tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" id="DAz-BE-6Ca">
<rect key="frame" x="0.0" y="0.0" width="600" height="268"/> <rect key="frame" x="0.0" y="0.0" width="600" height="268"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<prototypes> <prototypes>
<tableViewCell contentMode="scaleToFill" selectionStyle="default" accessoryType="disclosureIndicator" indentationWidth="10" reuseIdentifier="PaletteTableViewCell" id="G3X-70-BCD" customClass="PaletteTableViewCell" customModule="HardcoreDataDemo" customModuleProvider="target"> <tableViewCell contentMode="scaleToFill" selectionStyle="default" accessoryType="disclosureIndicator" indentationWidth="10" reuseIdentifier="PaletteTableViewCell" id="G3X-70-BCD" customClass="PaletteTableViewCell" customModule="HardcoreDataDemo" customModuleProvider="target">
<autoresizingMask key="autoresizingMask"/> <autoresizingMask key="autoresizingMask"/>
@@ -387,6 +386,11 @@
<navigationBar key="navigationBar" contentMode="scaleToFill" id="6XA-6M-yvZ"> <navigationBar key="navigationBar" contentMode="scaleToFill" id="6XA-6M-yvZ">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/> <rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/> <autoresizingMask key="autoresizingMask"/>
<color key="tintColor" red="0.75362819430000005" green="0.91446238759999998" blue="0.99948346610000005" alpha="1" colorSpace="calibratedRGB"/>
<color key="barTintColor" red="0.49803921580314636" green="0.49803921580314636" blue="0.49803921580314636" alpha="1" colorSpace="calibratedRGB"/>
<textAttributes key="titleTextAttributes">
<color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</textAttributes>
</navigationBar> </navigationBar>
<nil name="viewControllers"/> <nil name="viewControllers"/>
<connections> <connections>
@@ -406,6 +410,11 @@
<navigationBar key="navigationBar" contentMode="scaleToFill" id="wJo-mp-1pS"> <navigationBar key="navigationBar" contentMode="scaleToFill" id="wJo-mp-1pS">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/> <rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/> <autoresizingMask key="autoresizingMask"/>
<color key="tintColor" red="0.7536281943321228" green="0.9144623875617981" blue="0.99948346614837646" alpha="1" colorSpace="calibratedRGB"/>
<color key="barTintColor" red="0.49803921579999999" green="0.49803921579999999" blue="0.49803921579999999" alpha="1" colorSpace="calibratedRGB"/>
<textAttributes key="titleTextAttributes">
<color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</textAttributes>
</navigationBar> </navigationBar>
<nil name="viewControllers"/> <nil name="viewControllers"/>
<connections> <connections>
@@ -421,6 +430,6 @@
<image name="second" width="30" height="30"/> <image name="second" width="30" height="30"/>
</resources> </resources>
<inferredMetricsTieBreakers> <inferredMetricsTieBreakers>
<segue reference="fIB-GS-Ppk"/> <segue reference="hyN-De-zte"/>
</inferredMetricsTieBreakers> </inferredMetricsTieBreakers>
</document> </document>

View File

@@ -3,14 +3,11 @@
<entity name="Palette" representedClassName="HardcoreDataDemo.Palette"> <entity name="Palette" representedClassName="HardcoreDataDemo.Palette">
<attribute name="brightness" optional="YES" attributeType="Float" defaultValueString="0.0" syncable="YES"/> <attribute name="brightness" optional="YES" attributeType="Float" defaultValueString="0.0" syncable="YES"/>
<attribute name="colorName" optional="YES" transient="YES" attributeType="String" syncable="YES"/> <attribute name="colorName" optional="YES" transient="YES" attributeType="String" syncable="YES"/>
<attribute name="dateAdded" optional="YES" attributeType="Date">
<userInfo/>
</attribute>
<attribute name="hue" optional="YES" attributeType="Integer 32" defaultValueString="0.0" syncable="YES"/> <attribute name="hue" optional="YES" attributeType="Integer 32" defaultValueString="0.0" syncable="YES"/>
<attribute name="saturation" optional="YES" attributeType="Float" defaultValueString="0.0" syncable="YES"/> <attribute name="saturation" optional="YES" attributeType="Float" defaultValueString="0.0" syncable="YES"/>
<userInfo/> <userInfo/>
</entity> </entity>
<elements> <elements>
<element name="Palette" positionX="261" positionY="189" width="128" height="120"/> <element name="Palette" positionX="261" positionY="189" width="128" height="105"/>
</elements> </elements>
</model> </model>

View File

@@ -15,7 +15,7 @@ struct Shared {
static let palettes = HardcoreData.observeObjectList( static let palettes = HardcoreData.observeObjectList(
From(Palette), From(Palette),
GroupBy("colorName"), GroupBy("colorName"),
SortedBy(.Ascending("hue"), .Ascending("dateAdded")) SortedBy(.Ascending("hue"))
) )
} }
@@ -191,7 +191,7 @@ class ObjectListObserverDemoViewController: UITableViewController, ManagedObject
HardcoreData.beginAsynchronous { (transaction) -> Void in HardcoreData.beginAsynchronous { (transaction) -> Void in
transaction.deleteAll(From(Palette)) transaction.deleteAll(From(Palette))
transaction.commit { (result) -> Void in } transaction.commit()
} }
} }
@@ -202,7 +202,7 @@ class ObjectListObserverDemoViewController: UITableViewController, ManagedObject
let palette = transaction.create(Palette) let palette = transaction.create(Palette)
palette.setInitialValues() palette.setInitialValues()
transaction.commit { (result) -> Void in } transaction.commit()
} }
} }
} }

View File

@@ -56,7 +56,7 @@ class ObjectObserverDemoViewController: UIViewController, ManagedObjectObserver
let palette = transaction.create(Palette) let palette = transaction.create(Palette)
palette.setInitialValues() palette.setInitialValues()
transaction.commitAndWait() transaction.commit()
} }
let palette = HardcoreData.fetchOne(From(Palette), SortedBy(.Ascending("hue")))! let palette = HardcoreData.fetchOne(From(Palette), SortedBy(.Ascending("hue")))!
@@ -126,8 +126,7 @@ class ObjectObserverDemoViewController: UIViewController, ManagedObjectObserver
if let palette = transaction.fetch(self?.objectController?.object) { if let palette = transaction.fetch(self?.objectController?.object) {
palette.hue = Int32(hue) palette.hue = Int32(hue)
palette.dateAdded = NSDate() transaction.commit()
transaction.commit { (result) -> Void in }
} }
} }
} }
@@ -140,8 +139,7 @@ class ObjectObserverDemoViewController: UIViewController, ManagedObjectObserver
if let palette = transaction.fetch(self?.objectController?.object) { if let palette = transaction.fetch(self?.objectController?.object) {
palette.saturation = saturation palette.saturation = saturation
palette.dateAdded = NSDate() transaction.commit()
transaction.commit { (result) -> Void in }
} }
} }
} }
@@ -154,8 +152,7 @@ class ObjectObserverDemoViewController: UIViewController, ManagedObjectObserver
if let palette = transaction.fetch(self?.objectController?.object) { if let palette = transaction.fetch(self?.objectController?.object) {
palette.brightness = brightness palette.brightness = brightness
palette.dateAdded = NSDate() transaction.commit()
transaction.commit { (result) -> Void in }
} }
} }
} }
@@ -165,7 +162,7 @@ class ObjectObserverDemoViewController: UIViewController, ManagedObjectObserver
HardcoreData.beginAsynchronous { [weak self] (transaction) -> Void in HardcoreData.beginAsynchronous { [weak self] (transaction) -> Void in
transaction.delete(self?.objectController?.object) transaction.delete(self?.objectController?.object)
transaction.commit { (result) -> Void in } transaction.commit()
} }
} }
@@ -177,12 +174,11 @@ class ObjectObserverDemoViewController: UIViewController, ManagedObjectObserver
self.colorNameLabel?.textColor = color self.colorNameLabel?.textColor = color
self.colorView?.backgroundColor = color self.colorView?.backgroundColor = color
self.hsbLabel?.text = palette.colorText
let hue = palette.hue let hue = palette.hue
let saturation = palette.saturation let saturation = palette.saturation
let brightness = palette.brightness let brightness = palette.brightness
self.hsbLabel?.text = "H: \(hue)˚, S: \(Int(saturation * 100))%, B: \(Int(brightness * 100))%"
if Int32(self.hueSlider?.value ?? 0) != hue { if Int32(self.hueSlider?.value ?? 0) != hue {
self.hueSlider?.value = Float(hue) self.hueSlider?.value = Float(hue)

View File

@@ -16,7 +16,6 @@ import HardcoreData
class Palette: NSManagedObject { class Palette: NSManagedObject {
@NSManaged var dateAdded: NSDate
@NSManaged var hue: Int32 @NSManaged var hue: Int32
@NSManaged var saturation: Float @NSManaged var saturation: Float
@NSManaged var brightness: Float @NSManaged var brightness: Float
@@ -25,12 +24,8 @@ class Palette: NSManagedObject {
get { get {
let key = "colorName" let KVCKey = "colorName"
self.willAccessValueForKey(key) if let colorName = self.accessValueForKVCKey(KVCKey) as? String {
let value: AnyObject? = self.primitiveValueForKey(key)
self.didAccessValueForKey(key)
if let colorName = value as? String {
return colorName return colorName
} }
@@ -49,15 +44,12 @@ class Palette: NSManagedObject {
default: colorName = "Upper Reds" default: colorName = "Upper Reds"
} }
self.setPrimitiveValue(colorName, forKey: key) self.setPrimitiveValue(colorName, forKey: KVCKey)
return colorName return colorName
} }
set { set {
let key = "colorName" self.setValue(newValue, forKVCKey: "colorName")
self.willChangeValueForKey(key)
self.setPrimitiveValue(newValue, forKey: key)
self.didChangeValueForKey(key)
} }
} }
@@ -80,7 +72,6 @@ class Palette: NSManagedObject {
self.hue = Int32(arc4random_uniform(360)) self.hue = Int32(arc4random_uniform(360))
self.saturation = 1.0 self.saturation = 1.0
self.brightness = 0.5 self.brightness = Float(arc4random_uniform(70) + 30) / 100.0
self.dateAdded = NSDate()
} }
} }

View File

@@ -226,7 +226,7 @@ class HardcoreDataTests: XCTestCase {
) )
XCTAssertTrue(numberOfDeletedObjects2 == 2, "numberOfDeletedObjects2 == 2 (actual: \(numberOfDeletedObjects2))") XCTAssertTrue(numberOfDeletedObjects2 == 2, "numberOfDeletedObjects2 == 2 (actual: \(numberOfDeletedObjects2))")
transaction.commitAndWait() transaction.commit()
} }
let objs1 = HardcoreData.fetchAll(From(TestEntity1)) let objs1 = HardcoreData.fetchAll(From(TestEntity1))