diff --git a/.travis.yml b/.travis.yml index 0c4ba7d..1233073 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ language: objective-c -osx_image: xcode8.3.2 +osx_image: xcode8.3 sudo: false git: submodules: false diff --git a/CoreStoreTests/DynamicModelTests.swift b/CoreStoreTests/DynamicModelTests.swift index 02fea11..b63c708 100644 --- a/CoreStoreTests/DynamicModelTests.swift +++ b/CoreStoreTests/DynamicModelTests.swift @@ -28,12 +28,18 @@ import XCTest @testable import CoreStore +#if os(OSX) + typealias Color = NSColor +#else + + typealias Color = UIColor +#endif class Animal: CoreStoreObject { let species = Value.Required("species", default: "Swift") let master = Relationship.ToOne("master") - let color = Transformable.Optional("color") + let color = Transformable.Optional("color") } class Dog: Animal { @@ -102,7 +108,7 @@ class DynamicModelTests: BaseTestDataTestCase { XCTAssertEqual(animal.species.value, "Sparrow") animal.color .= .yellow - XCTAssertEqual(animal.color.value, UIColor.yellow) + XCTAssertEqual(animal.color.value, Color.yellow) let dog = transaction.create(Into()) XCTAssertEqual(dog.species.value, "Swift") @@ -168,7 +174,6 @@ class DynamicModelTests: BaseTestDataTestCase { success: { fetchDone.fulfill() - withExtendedLifetime(stack, {}) }, failure: { _ in diff --git a/Sources/CSUnsafeDataTransaction.swift b/Sources/CSUnsafeDataTransaction.swift index e0f0ee7..002bae3 100644 --- a/Sources/CSUnsafeDataTransaction.swift +++ b/Sources/CSUnsafeDataTransaction.swift @@ -47,6 +47,10 @@ public final class CSUnsafeDataTransaction: CSBaseDataTransaction { self.bridgeToSwift.context.saveAsynchronouslyWithCompletion { (_, error) in + defer { + + withExtendedLifetime(self, {}) + } if let error = error { failure?(error.bridgeToObjectiveC) @@ -55,7 +59,6 @@ public final class CSUnsafeDataTransaction: CSBaseDataTransaction { success?() } - withExtendedLifetime(self, {}) } } @@ -217,6 +220,10 @@ public final class CSUnsafeDataTransaction: CSBaseDataTransaction { self.bridgeToSwift.context.saveAsynchronouslyWithCompletion { (hasChanges, error) in + defer { + + withExtendedLifetime(self, {}) + } if let error = error { completion?(SaveResult(error).bridgeToObjectiveC) @@ -225,7 +232,6 @@ public final class CSUnsafeDataTransaction: CSBaseDataTransaction { completion?(SaveResult(hasChanges: hasChanges).bridgeToObjectiveC) } - withExtendedLifetime(self, {}) } } diff --git a/Sources/DataStack+Transaction.swift b/Sources/DataStack+Transaction.swift index 68c4b38..52a09c7 100644 --- a/Sources/DataStack+Transaction.swift +++ b/Sources/DataStack+Transaction.swift @@ -63,7 +63,7 @@ public extension DataStack { defer { - withExtendedLifetime(transaction, {}) + withExtendedLifetime((self, transaction), {}) } let userInfo: T do { @@ -112,7 +112,7 @@ public extension DataStack { defer { - withExtendedLifetime(transaction, {}) + withExtendedLifetime((self, transaction), {}) } let userInfo: T do {