diff --git a/HardcoreData.xcodeproj/project.pbxproj b/HardcoreData.xcodeproj/project.pbxproj index 95406e8..254c18b 100644 --- a/HardcoreData.xcodeproj/project.pbxproj +++ b/HardcoreData.xcodeproj/project.pbxproj @@ -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 = ""; 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 = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; + B503FAE61AFDE20C00F90881 /* NSManagedObject+Convenience.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSManagedObject+Convenience.swift"; sourceTree = ""; }; B50DD9DC1ABD34F800D62F2B /* From.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = From.swift; sourceTree = ""; }; B52B68B91AAB46AD00CE7F48 /* ManagedObjectController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ManagedObjectController.swift; sourceTree = ""; }; B52B68BB1AAB46BD00CE7F48 /* ManagedObjectListController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ManagedObjectListController.swift; sourceTree = ""; }; @@ -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 = ""; }; + B503FAE31AFDE1E500F90881 /* Convenience Helpers */ = { + isa = PBXGroup; + children = ( + B503FAE61AFDE20C00F90881 /* NSManagedObject+Convenience.swift */, + ); + name = "Convenience Helpers"; + sourceTree = ""; + }; 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 */, diff --git a/HardcoreData/AsynchronousDataTransaction.swift b/HardcoreData/AsynchronousDataTransaction.swift index e9e0269..2d1a86e 100644 --- a/HardcoreData/AsynchronousDataTransaction.swift +++ b/HardcoreData/AsynchronousDataTransaction.swift @@ -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() { diff --git a/HardcoreData/From.swift b/HardcoreData/From.swift index 25e5729..2fa12aa 100644 --- a/HardcoreData/From.swift +++ b/HardcoreData/From.swift @@ -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 diff --git a/HardcoreData/NSManagedObject+Convenience.swift b/HardcoreData/NSManagedObject+Convenience.swift new file mode 100644 index 0000000..0f9c6ee --- /dev/null +++ b/HardcoreData/NSManagedObject+Convenience.swift @@ -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) + } +} \ No newline at end of file diff --git a/HardcoreData/SynchronousDataTransaction.swift b/HardcoreData/SynchronousDataTransaction.swift index bcef990..fb8c170 100644 --- a/HardcoreData/SynchronousDataTransaction.swift +++ b/HardcoreData/SynchronousDataTransaction.swift @@ -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() { diff --git a/HardcoreDataDemo/HardcoreDataDemo.xcodeproj/project.xcworkspace/xcshareddata/HardcoreDataDemo.xccheckout b/HardcoreDataDemo/HardcoreDataDemo.xcodeproj/project.xcworkspace/xcshareddata/HardcoreDataDemo.xccheckout index 3247538..d6128a7 100644 --- a/HardcoreDataDemo/HardcoreDataDemo.xcodeproj/project.xcworkspace/xcshareddata/HardcoreDataDemo.xccheckout +++ b/HardcoreDataDemo/HardcoreDataDemo.xcodeproj/project.xcworkspace/xcshareddata/HardcoreDataDemo.xccheckout @@ -22,7 +22,7 @@ 4B60F1BCB491FF717C56441AE7783C74F417BE48 ../../.. 8B2E522D57154DFA93A06982C36315ECBEA4FA97 - ../../..Libraries/GCDKit/ + ../../..Libraries/GCDKit IDESourceControlProjectURL github.com:JohnEstropia/HardcoreData.git diff --git a/HardcoreDataDemo/HardcoreDataDemo/AppDelegate.swift b/HardcoreDataDemo/HardcoreDataDemo/AppDelegate.swift index a00c390..7938abb 100644 --- a/HardcoreDataDemo/HardcoreDataDemo/AppDelegate.swift +++ b/HardcoreDataDemo/HardcoreDataDemo/AppDelegate.swift @@ -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 } } diff --git a/HardcoreDataDemo/HardcoreDataDemo/Base.lproj/Main.storyboard b/HardcoreDataDemo/HardcoreDataDemo/Base.lproj/Main.storyboard index c7cdc67..ff45e22 100644 --- a/HardcoreDataDemo/HardcoreDataDemo/Base.lproj/Main.storyboard +++ b/HardcoreDataDemo/HardcoreDataDemo/Base.lproj/Main.storyboard @@ -120,20 +120,20 @@ - - + + - - + + - - + + @@ -269,7 +269,6 @@ - @@ -387,6 +386,11 @@ + + + + + @@ -406,6 +410,11 @@ + + + + + @@ -421,6 +430,6 @@ - + diff --git a/HardcoreDataDemo/HardcoreDataDemo/HardcoreDataDemo.xcdatamodeld/HardcoreDataDemo.xcdatamodel/contents b/HardcoreDataDemo/HardcoreDataDemo/HardcoreDataDemo.xcdatamodeld/HardcoreDataDemo.xcdatamodel/contents index 1939d96..fecdf73 100644 --- a/HardcoreDataDemo/HardcoreDataDemo/HardcoreDataDemo.xcdatamodeld/HardcoreDataDemo.xcdatamodel/contents +++ b/HardcoreDataDemo/HardcoreDataDemo/HardcoreDataDemo.xcdatamodeld/HardcoreDataDemo.xcdatamodel/contents @@ -3,14 +3,11 @@ - - - - + \ No newline at end of file diff --git a/HardcoreDataDemo/HardcoreDataDemo/List and Object Observers Demo/ObjectListObserverDemoViewController.swift b/HardcoreDataDemo/HardcoreDataDemo/List and Object Observers Demo/ObjectListObserverDemoViewController.swift index 3821eb3..7c171e2 100644 --- a/HardcoreDataDemo/HardcoreDataDemo/List and Object Observers Demo/ObjectListObserverDemoViewController.swift +++ b/HardcoreDataDemo/HardcoreDataDemo/List and Object Observers Demo/ObjectListObserverDemoViewController.swift @@ -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() } } } diff --git a/HardcoreDataDemo/HardcoreDataDemo/List and Object Observers Demo/ObjectObserverDemoViewController.swift b/HardcoreDataDemo/HardcoreDataDemo/List and Object Observers Demo/ObjectObserverDemoViewController.swift index d6dded8..b23c1d7 100644 --- a/HardcoreDataDemo/HardcoreDataDemo/List and Object Observers Demo/ObjectObserverDemoViewController.swift +++ b/HardcoreDataDemo/HardcoreDataDemo/List and Object Observers Demo/ObjectObserverDemoViewController.swift @@ -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) diff --git a/HardcoreDataDemo/HardcoreDataDemo/List and Object Observers Demo/Palette.swift b/HardcoreDataDemo/HardcoreDataDemo/List and Object Observers Demo/Palette.swift index fc59d41..e1538c2 100644 --- a/HardcoreDataDemo/HardcoreDataDemo/List and Object Observers Demo/Palette.swift +++ b/HardcoreDataDemo/HardcoreDataDemo/List and Object Observers Demo/Palette.swift @@ -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 } } diff --git a/HardcoreDataTests/HardcoreDataTests.swift b/HardcoreDataTests/HardcoreDataTests.swift index 0ac7eb2..c8c0a75 100644 --- a/HardcoreDataTests/HardcoreDataTests.swift +++ b/HardcoreDataTests/HardcoreDataTests.swift @@ -226,7 +226,7 @@ class HardcoreDataTests: XCTestCase { ) XCTAssertTrue(numberOfDeletedObjects2 == 2, "numberOfDeletedObjects2 == 2 (actual: \(numberOfDeletedObjects2))") - transaction.commitAndWait() + transaction.commit() } let objs1 = HardcoreData.fetchAll(From(TestEntity1))