mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-01-15 05:33:31 +01:00
renamed commitAndWait() to overload commit()
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
2F03A54019C5C6DA005002A5 /* HardcoreDataTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F03A53F19C5C6DA005002A5 /* HardcoreDataTests.swift */; };
|
||||
2F03A54D19C5C872005002A5 /* CoreData.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2F03A54C19C5C872005002A5 /* CoreData.framework */; };
|
||||
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 */; };
|
||||
B52B68BA1AAB46AD00CE7F48 /* ManagedObjectController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B52B68B91AAB46AD00CE7F48 /* ManagedObjectController.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; };
|
||||
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; };
|
||||
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>"; };
|
||||
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>"; };
|
||||
@@ -191,6 +193,7 @@
|
||||
B5F409E51A8B11B600A228EA /* Logging */,
|
||||
B5E126531A7DCCE400AD8B39 /* Fetching and Querying */,
|
||||
B52B68B61AAB45FB00CE7F48 /* Observing */,
|
||||
B503FAE31AFDE1E500F90881 /* Convenience Helpers */,
|
||||
B5D808141A34945A00A44484 /* Internal */,
|
||||
2F03A53319C5C6DA005002A5 /* Supporting Files */,
|
||||
);
|
||||
@@ -237,6 +240,14 @@
|
||||
name = Frameworks;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
B503FAE31AFDE1E500F90881 /* Convenience Helpers */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
B503FAE61AFDE20C00F90881 /* NSManagedObject+Convenience.swift */,
|
||||
);
|
||||
name = "Convenience Helpers";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
B52B68B61AAB45FB00CE7F48 /* Observing */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
@@ -523,6 +534,7 @@
|
||||
B5CFF23E19FD1D1C00D6DFC4 /* NSManagedObjectContext+HardcoreData.swift in Sources */,
|
||||
B54A9F071AA7654400AFEC05 /* DataStack+Querying.swift in Sources */,
|
||||
B5E126571A7DCE5900AD8B39 /* SortedBy.swift in Sources */,
|
||||
B503FAE71AFDE20C00F90881 /* NSManagedObject+Convenience.swift in Sources */,
|
||||
B54D53071AB3538500D55BA8 /* QueryClause.swift in Sources */,
|
||||
B5F409EF1A8B243D00A228EA /* BaseDataTransaction+Querying.swift in Sources */,
|
||||
2F291E2719C6D3CF007AF63F /* HardcoreData.swift in Sources */,
|
||||
|
||||
@@ -38,7 +38,7 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
|
||||
// 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.
|
||||
*/
|
||||
@@ -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.
|
||||
*/
|
||||
public func commitAndWait() {
|
||||
public func commit() {
|
||||
|
||||
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.")
|
||||
@@ -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.
|
||||
: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
|
||||
|
||||
/**
|
||||
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
|
||||
: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
|
||||
: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
|
||||
*/
|
||||
@@ -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() {
|
||||
|
||||
|
||||
@@ -2,8 +2,25 @@
|
||||
// From.swift
|
||||
// HardcoreData
|
||||
//
|
||||
// Created by John Rommel Estropia on 2015/03/21.
|
||||
// Copyright (c) 2015 John Rommel Estropia. All rights reserved.
|
||||
// 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
|
||||
|
||||
49
HardcoreData/NSManagedObject+Convenience.swift
Normal file
49
HardcoreData/NSManagedObject+Convenience.swift
Normal 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)
|
||||
}
|
||||
}
|
||||
@@ -38,11 +38,11 @@ public final class SynchronousDataTransaction: BaseDataTransaction {
|
||||
// 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.
|
||||
*/
|
||||
public func commitAndWait() {
|
||||
public func commit() {
|
||||
|
||||
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.")
|
||||
@@ -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.
|
||||
: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
|
||||
|
||||
/**
|
||||
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
|
||||
: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
|
||||
: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
|
||||
*/
|
||||
@@ -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() {
|
||||
|
||||
|
||||
@@ -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/HardcoreData.git</string>
|
||||
|
||||
@@ -21,7 +21,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||
|
||||
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
|
||||
|
||||
HardcoreData.defaultStack.addSQLiteStore()
|
||||
HardcoreData.defaultStack.addSQLiteStore(resetStoreOnMigrationFailure: true)
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,20 +120,20 @@
|
||||
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<slider opaque="NO" contentMode="scaleToFill" misplaced="YES" 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"/>
|
||||
<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="148" width="488" height="31"/>
|
||||
<connections>
|
||||
<action selector="hueSliderValueDidChange:" destination="dX3-kR-CYC" eventType="valueChanged" id="9Hy-3h-llE"/>
|
||||
</connections>
|
||||
</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">
|
||||
<rect key="frame" x="98" y="187" width="488" height="31"/>
|
||||
<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="186" width="488" height="31"/>
|
||||
<connections>
|
||||
<action selector="saturationSliderValueDidChange:" destination="dX3-kR-CYC" eventType="valueChanged" id="qtU-ua-ZTc"/>
|
||||
</connections>
|
||||
</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">
|
||||
<rect key="frame" x="98" y="225" width="488" height="31"/>
|
||||
<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="224" width="488" height="31"/>
|
||||
<connections>
|
||||
<action selector="brightnessSliderValueDidChange:" destination="dX3-kR-CYC" eventType="valueChanged" id="F09-EP-2iD"/>
|
||||
</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">
|
||||
<rect key="frame" x="0.0" y="0.0" width="600" height="268"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
|
||||
<prototypes>
|
||||
<tableViewCell contentMode="scaleToFill" selectionStyle="default" accessoryType="disclosureIndicator" indentationWidth="10" reuseIdentifier="PaletteTableViewCell" id="G3X-70-BCD" customClass="PaletteTableViewCell" customModule="HardcoreDataDemo" customModuleProvider="target">
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
@@ -387,6 +386,11 @@
|
||||
<navigationBar key="navigationBar" contentMode="scaleToFill" id="6XA-6M-yvZ">
|
||||
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
|
||||
<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>
|
||||
<nil name="viewControllers"/>
|
||||
<connections>
|
||||
@@ -406,6 +410,11 @@
|
||||
<navigationBar key="navigationBar" contentMode="scaleToFill" id="wJo-mp-1pS">
|
||||
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
|
||||
<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>
|
||||
<nil name="viewControllers"/>
|
||||
<connections>
|
||||
@@ -421,6 +430,6 @@
|
||||
<image name="second" width="30" height="30"/>
|
||||
</resources>
|
||||
<inferredMetricsTieBreakers>
|
||||
<segue reference="fIB-GS-Ppk"/>
|
||||
<segue reference="hyN-De-zte"/>
|
||||
</inferredMetricsTieBreakers>
|
||||
</document>
|
||||
|
||||
@@ -3,14 +3,11 @@
|
||||
<entity name="Palette" representedClassName="HardcoreDataDemo.Palette">
|
||||
<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="dateAdded" optional="YES" attributeType="Date">
|
||||
<userInfo/>
|
||||
</attribute>
|
||||
<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"/>
|
||||
<userInfo/>
|
||||
</entity>
|
||||
<elements>
|
||||
<element name="Palette" positionX="261" positionY="189" width="128" height="120"/>
|
||||
<element name="Palette" positionX="261" positionY="189" width="128" height="105"/>
|
||||
</elements>
|
||||
</model>
|
||||
@@ -15,7 +15,7 @@ struct Shared {
|
||||
static let palettes = HardcoreData.observeObjectList(
|
||||
From(Palette),
|
||||
GroupBy("colorName"),
|
||||
SortedBy(.Ascending("hue"), .Ascending("dateAdded"))
|
||||
SortedBy(.Ascending("hue"))
|
||||
)
|
||||
}
|
||||
|
||||
@@ -191,7 +191,7 @@ class ObjectListObserverDemoViewController: UITableViewController, ManagedObject
|
||||
HardcoreData.beginAsynchronous { (transaction) -> Void in
|
||||
|
||||
transaction.deleteAll(From(Palette))
|
||||
transaction.commit { (result) -> Void in }
|
||||
transaction.commit()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,7 +202,7 @@ class ObjectListObserverDemoViewController: UITableViewController, ManagedObject
|
||||
let palette = transaction.create(Palette)
|
||||
palette.setInitialValues()
|
||||
|
||||
transaction.commit { (result) -> Void in }
|
||||
transaction.commit()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ class ObjectObserverDemoViewController: UIViewController, ManagedObjectObserver
|
||||
let palette = transaction.create(Palette)
|
||||
palette.setInitialValues()
|
||||
|
||||
transaction.commitAndWait()
|
||||
transaction.commit()
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
palette.hue = Int32(hue)
|
||||
palette.dateAdded = NSDate()
|
||||
transaction.commit { (result) -> Void in }
|
||||
transaction.commit()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -140,8 +139,7 @@ class ObjectObserverDemoViewController: UIViewController, ManagedObjectObserver
|
||||
if let palette = transaction.fetch(self?.objectController?.object) {
|
||||
|
||||
palette.saturation = saturation
|
||||
palette.dateAdded = NSDate()
|
||||
transaction.commit { (result) -> Void in }
|
||||
transaction.commit()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -154,8 +152,7 @@ class ObjectObserverDemoViewController: UIViewController, ManagedObjectObserver
|
||||
if let palette = transaction.fetch(self?.objectController?.object) {
|
||||
|
||||
palette.brightness = brightness
|
||||
palette.dateAdded = NSDate()
|
||||
transaction.commit { (result) -> Void in }
|
||||
transaction.commit()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -165,7 +162,7 @@ class ObjectObserverDemoViewController: UIViewController, ManagedObjectObserver
|
||||
HardcoreData.beginAsynchronous { [weak self] (transaction) -> Void in
|
||||
|
||||
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.colorView?.backgroundColor = color
|
||||
|
||||
self.hsbLabel?.text = palette.colorText
|
||||
|
||||
let hue = palette.hue
|
||||
let saturation = palette.saturation
|
||||
let brightness = palette.brightness
|
||||
|
||||
self.hsbLabel?.text = "H: \(hue)˚, S: \(Int(saturation * 100))%, B: \(Int(brightness * 100))%"
|
||||
|
||||
if Int32(self.hueSlider?.value ?? 0) != hue {
|
||||
|
||||
self.hueSlider?.value = Float(hue)
|
||||
|
||||
@@ -16,7 +16,6 @@ import HardcoreData
|
||||
|
||||
class Palette: NSManagedObject {
|
||||
|
||||
@NSManaged var dateAdded: NSDate
|
||||
@NSManaged var hue: Int32
|
||||
@NSManaged var saturation: Float
|
||||
@NSManaged var brightness: Float
|
||||
@@ -25,12 +24,8 @@ class Palette: NSManagedObject {
|
||||
|
||||
get {
|
||||
|
||||
let key = "colorName"
|
||||
self.willAccessValueForKey(key)
|
||||
let value: AnyObject? = self.primitiveValueForKey(key)
|
||||
self.didAccessValueForKey(key)
|
||||
|
||||
if let colorName = value as? String {
|
||||
let KVCKey = "colorName"
|
||||
if let colorName = self.accessValueForKVCKey(KVCKey) as? String {
|
||||
|
||||
return colorName
|
||||
}
|
||||
@@ -49,15 +44,12 @@ class Palette: NSManagedObject {
|
||||
default: colorName = "Upper Reds"
|
||||
}
|
||||
|
||||
self.setPrimitiveValue(colorName, forKey: key)
|
||||
self.setPrimitiveValue(colorName, forKey: KVCKey)
|
||||
return colorName
|
||||
}
|
||||
set {
|
||||
|
||||
let key = "colorName"
|
||||
self.willChangeValueForKey(key)
|
||||
self.setPrimitiveValue(newValue, forKey: key)
|
||||
self.didChangeValueForKey(key)
|
||||
self.setValue(newValue, forKVCKey: "colorName")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,7 +72,6 @@ class Palette: NSManagedObject {
|
||||
|
||||
self.hue = Int32(arc4random_uniform(360))
|
||||
self.saturation = 1.0
|
||||
self.brightness = 0.5
|
||||
self.dateAdded = NSDate()
|
||||
self.brightness = Float(arc4random_uniform(70) + 30) / 100.0
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,7 +226,7 @@ class HardcoreDataTests: XCTestCase {
|
||||
)
|
||||
XCTAssertTrue(numberOfDeletedObjects2 == 2, "numberOfDeletedObjects2 == 2 (actual: \(numberOfDeletedObjects2))")
|
||||
|
||||
transaction.commitAndWait()
|
||||
transaction.commit()
|
||||
}
|
||||
|
||||
let objs1 = HardcoreData.fetchAll(From(TestEntity1))
|
||||
|
||||
Reference in New Issue
Block a user