user #keyPath() for keys in demo app and in unit tests

This commit is contained in:
John Estropia
2016-09-09 17:05:55 +09:00
parent 0fa2a23461
commit e5245a0e5b
27 changed files with 1002 additions and 851 deletions

View File

@@ -1427,9 +1427,11 @@
}; };
B52DD1731BE1F8CC00949AFE = { B52DD1731BE1F8CC00949AFE = {
CreatedOnToolsVersion = 7.1; CreatedOnToolsVersion = 7.1;
LastSwiftMigration = 0800;
}; };
B52DD17C1BE1F8CC00949AFE = { B52DD17C1BE1F8CC00949AFE = {
CreatedOnToolsVersion = 7.1; CreatedOnToolsVersion = 7.1;
LastSwiftMigration = 0800;
}; };
B563216E1BD65082006C9394 = { B563216E1BD65082006C9394 = {
CreatedOnToolsVersion = 7.0.1; CreatedOnToolsVersion = 7.0.1;
@@ -2369,6 +2371,7 @@
SDKROOT = macosx; SDKROOT = macosx;
SKIP_INSTALL = YES; SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
}; };
name = Debug; name = Debug;
}; };
@@ -2391,6 +2394,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
SDKROOT = macosx; SDKROOT = macosx;
SKIP_INSTALL = YES; SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
}; };
name = Release; name = Release;
}; };
@@ -2409,6 +2413,7 @@
SDKROOT = macosx; SDKROOT = macosx;
SWIFT_OBJC_BRIDGING_HEADER = "CoreStoreTests/CoreStoreTests-Bridging-Header.h"; SWIFT_OBJC_BRIDGING_HEADER = "CoreStoreTests/CoreStoreTests-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
}; };
name = Debug; name = Debug;
}; };
@@ -2427,6 +2432,7 @@
PRODUCT_NAME = CoreStoreTests; PRODUCT_NAME = CoreStoreTests;
SDKROOT = macosx; SDKROOT = macosx;
SWIFT_OBJC_BRIDGING_HEADER = "CoreStoreTests/CoreStoreTests-Bridging-Header.h"; SWIFT_OBJC_BRIDGING_HEADER = "CoreStoreTests/CoreStoreTests-Bridging-Header.h";
SWIFT_VERSION = 3.0;
}; };
name = Release; name = Release;
}; };

View File

@@ -168,7 +168,7 @@ class FetchingAndQueryingDemoViewController: UIViewController, UITableViewDataSo
return Static.timeZonesStack.fetchAll( return Static.timeZonesStack.fetchAll(
From<TimeZone>(), From<TimeZone>(),
OrderBy(.ascending("name")) OrderBy(.ascending(#keyPath(TimeZone.name)))
)! )!
} }
), ),
@@ -178,8 +178,8 @@ class FetchingAndQueryingDemoViewController: UIViewController, UITableViewDataSo
return Static.timeZonesStack.fetchAll( return Static.timeZonesStack.fetchAll(
From<TimeZone>(), From<TimeZone>(),
Where("%K BEGINSWITH[c] %@", "name", "Asia"), Where("%K BEGINSWITH[c] %@", #keyPath(TimeZone.name), "Asia"),
OrderBy(.ascending("secondsFromGMT")) OrderBy(.ascending(#keyPath(TimeZone.secondsFromGMT)))
)! )!
} }
), ),
@@ -189,9 +189,9 @@ class FetchingAndQueryingDemoViewController: UIViewController, UITableViewDataSo
return Static.timeZonesStack.fetchAll( return Static.timeZonesStack.fetchAll(
From<TimeZone>(), From<TimeZone>(),
Where("%K BEGINSWITH[c] %@", "name", "America") Where("%K BEGINSWITH[c] %@", #keyPath(TimeZone.name), "America")
|| Where("%K BEGINSWITH[c] %@", "name", "Europe"), || Where("%K BEGINSWITH[c] %@", #keyPath(TimeZone.name), "Europe"),
OrderBy(.ascending("secondsFromGMT")) OrderBy(.ascending(#keyPath(TimeZone.secondsFromGMT)))
)! )!
} }
), ),
@@ -201,8 +201,8 @@ class FetchingAndQueryingDemoViewController: UIViewController, UITableViewDataSo
return Static.timeZonesStack.fetchAll( return Static.timeZonesStack.fetchAll(
From<TimeZone>(), From<TimeZone>(),
!Where("%K BEGINSWITH[c] %@", "name", "America"), !Where("%K BEGINSWITH[c] %@", #keyPath(TimeZone.name), "America"),
OrderBy(.ascending("secondsFromGMT")) OrderBy(.ascending(#keyPath(TimeZone.secondsFromGMT)))
)! )!
} }
), ),
@@ -213,7 +213,7 @@ class FetchingAndQueryingDemoViewController: UIViewController, UITableViewDataSo
return Static.timeZonesStack.fetchAll( return Static.timeZonesStack.fetchAll(
From<TimeZone>(), From<TimeZone>(),
Where("hasDaylightSavingTime", isEqualTo: true), Where("hasDaylightSavingTime", isEqualTo: true),
OrderBy(.ascending("name")) OrderBy(.ascending(#keyPath(TimeZone.name)))
)! )!
} }
) )
@@ -226,7 +226,7 @@ class FetchingAndQueryingDemoViewController: UIViewController, UITableViewDataSo
return Static.timeZonesStack.queryValue( return Static.timeZonesStack.queryValue(
From<TimeZone>(), From<TimeZone>(),
Select<NSNumber>(.count("name")) Select<NSNumber>(.count(#keyPath(TimeZone.name)))
)! )!
} }
), ),
@@ -236,8 +236,8 @@ class FetchingAndQueryingDemoViewController: UIViewController, UITableViewDataSo
return Static.timeZonesStack.queryValue( return Static.timeZonesStack.queryValue(
From<TimeZone>(), From<TimeZone>(),
Select<String>("abbreviation"), Select<String>(#keyPath(TimeZone.abbreviation)),
Where("%K ENDSWITH[c] %@", "name", "Tokyo") Where("%K ENDSWITH[c] %@", #keyPath(TimeZone.name), "Tokyo")
)! )!
} }
), ),
@@ -247,8 +247,8 @@ class FetchingAndQueryingDemoViewController: UIViewController, UITableViewDataSo
return Static.timeZonesStack.queryAttributes( return Static.timeZonesStack.queryAttributes(
From<TimeZone>(), From<TimeZone>(),
Select<NSDictionary>("name", "abbreviation"), Select<NSDictionary>(#keyPath(TimeZone.name), #keyPath(TimeZone.abbreviation)),
OrderBy(.ascending("name")) OrderBy(.ascending(#keyPath(TimeZone.name)))
)! )!
} }
), ),
@@ -258,9 +258,9 @@ class FetchingAndQueryingDemoViewController: UIViewController, UITableViewDataSo
return Static.timeZonesStack.queryAttributes( return Static.timeZonesStack.queryAttributes(
From<TimeZone>(), From<TimeZone>(),
Select<NSDictionary>(.count("abbreviation"), "abbreviation"), Select<NSDictionary>(.count(#keyPath(TimeZone.abbreviation)), #keyPath(TimeZone.abbreviation)),
GroupBy("abbreviation"), GroupBy(#keyPath(TimeZone.abbreviation)),
OrderBy(.ascending("secondsFromGMT"), .ascending("name")) OrderBy(.ascending(#keyPath(TimeZone.secondsFromGMT)), .ascending(#keyPath(TimeZone.name)))
)! )!
} }
), ),
@@ -271,11 +271,11 @@ class FetchingAndQueryingDemoViewController: UIViewController, UITableViewDataSo
return Static.timeZonesStack.queryAttributes( return Static.timeZonesStack.queryAttributes(
From<TimeZone>(), From<TimeZone>(),
Select<NSDictionary>( Select<NSDictionary>(
.count("hasDaylightSavingTime", as: "numberOfCountries"), .count(#keyPath(TimeZone.hasDaylightSavingTime), as: "numberOfCountries"),
"hasDaylightSavingTime" #keyPath(TimeZone.hasDaylightSavingTime)
), ),
GroupBy("hasDaylightSavingTime"), GroupBy(#keyPath(TimeZone.hasDaylightSavingTime)),
OrderBy(.descending("hasDaylightSavingTime")) OrderBy(.descending(#keyPath(TimeZone.hasDaylightSavingTime)))
)! )!
} }
) )

View File

@@ -33,8 +33,8 @@ private struct Static {
switch self { switch self {
case .all: return Where(true) case .all: return Where(true)
case .light: return Where("brightness >= 0.9") case .light: return Where("%K >= %@", #keyPath(Palette.brightness), 0.9)
case .dark: return Where("brightness <= 0.4") case .dark: return Where("%K <= %@", #keyPath(Palette.brightness), 0.4)
} }
} }
} }
@@ -59,8 +59,8 @@ private struct Static {
return CoreStore.monitorSectionedList( return CoreStore.monitorSectionedList(
From<Palette>(), From<Palette>(),
SectionBy("colorName"), SectionBy(#keyPath(Palette.colorName)),
OrderBy(.ascending("hue")) OrderBy(.ascending(#keyPath(Palette.hue)))
) )
}() }()
} }

View File

@@ -50,7 +50,7 @@ class ObjectObserverDemoViewController: UIViewController, ObjectObserver {
required init?(coder aDecoder: NSCoder) { required init?(coder aDecoder: NSCoder) {
if let palette = CoreStore.fetchOne(From<Palette>(), OrderBy(.ascending("hue"))) { if let palette = CoreStore.fetchOne(From<Palette>(), OrderBy(.ascending(#keyPath(Palette.hue)))) {
self.monitor = CoreStore.monitorObject(palette) self.monitor = CoreStore.monitorObject(palette)
} }
@@ -64,7 +64,7 @@ class ObjectObserverDemoViewController: UIViewController, ObjectObserver {
_ = transaction.commitAndWait() _ = transaction.commitAndWait()
} }
let palette = CoreStore.fetchOne(From<Palette>(), OrderBy(.ascending("hue")))! let palette = CoreStore.fetchOne(From<Palette>(), OrderBy(.ascending(#keyPath(Palette.hue))))!
self.monitor = CoreStore.monitorObject(palette) self.monitor = CoreStore.monitorObject(palette)
} }
@@ -176,15 +176,15 @@ class ObjectObserverDemoViewController: UIViewController, ObjectObserver {
self.hsbLabel?.text = palette.colorText self.hsbLabel?.text = palette.colorText
if changedKeys == nil || changedKeys?.contains("hue") == true { if changedKeys == nil || changedKeys?.contains(#keyPath(Palette.hue)) == true {
self.hueSlider?.value = Float(palette.hue) self.hueSlider?.value = Float(palette.hue)
} }
if changedKeys == nil || changedKeys?.contains("saturation") == true { if changedKeys == nil || changedKeys?.contains(#keyPath(Palette.saturation)) == true {
self.saturationSlider?.value = palette.saturation self.saturationSlider?.value = palette.saturation
} }
if changedKeys == nil || changedKeys?.contains("brightness") == true { if changedKeys == nil || changedKeys?.contains(#keyPath(Palette.brightness)) == true {
self.brightnessSlider?.value = palette.brightness self.brightnessSlider?.value = palette.brightness
} }

View File

@@ -24,7 +24,7 @@ class Palette: NSManagedObject {
get { get {
let KVCKey = "colorName" let KVCKey = #keyPath(Palette.colorName)
if let colorName = self.accessValueForKVCKey(KVCKey) as? String { if let colorName = self.accessValueForKVCKey(KVCKey) as? String {
return colorName return colorName
@@ -49,7 +49,7 @@ class Palette: NSManagedObject {
} }
set { set {
self.setValue(newValue, forKVCKey: "colorName") self.setValue(newValue, forKVCKey: #keyPath(Palette.colorName))
} }
} }

View File

@@ -241,7 +241,7 @@ class MigrationsDemoViewController: UIViewController, ListObserver, UITableViewD
let count = dataStack.queryValue( let count = dataStack.queryValue(
From(model.entityType), From(model.entityType),
Select<Int>(.count("dna")))! Select<Int>(.count(#keyPath(OrganismProtocol.dna))))!
if count > 0 { if count > 0 {
self.setEnabled(true) self.setEnabled(true)

View File

@@ -16,8 +16,14 @@ class OrganismV2ToV3MigrationPolicy: NSEntityMigrationPolicy {
for dInstance in manager.destinationInstances(forEntityMappingName: mapping.name, sourceInstances: [sInstance]) { for dInstance in manager.destinationInstances(forEntityMappingName: mapping.name, sourceInstances: [sInstance]) {
dInstance.setValue(false, forKey: "hasVertebrae") dInstance.setValue(
dInstance.setValue(sInstance.value(forKey: "numberOfFlippers"), forKey: "numberOfLimbs") false,
forKey: #keyPath(OrganismV3.hasVertebrae)
)
dInstance.setValue(
sInstance.value(forKey: #keyPath(OrganismV2.numberOfFlippers)),
forKey: #keyPath(OrganismV3.numberOfLimbs)
)
} }
} }
} }

View File

@@ -140,7 +140,7 @@ class TransactionsDemoViewController: UIViewController, MKMapViewDelegate, Objec
mapView.setCenter(object.coordinate, animated: true) mapView.setCenter(object.coordinate, animated: true)
mapView.selectAnnotation(object, animated: true) mapView.selectAnnotation(object, animated: true)
if changedPersistentKeys.contains("latitude") || changedPersistentKeys.contains("longitude") { if changedPersistentKeys.contains(#keyPath(Place.latitude) || changedPersistentKeys.contains(#keyPath(Place.longitude)) {
self.geocode(place: object) self.geocode(place: object)
} }

File diff suppressed because it is too large Load Diff

View File

@@ -66,7 +66,7 @@ final class GroupByTests: BaseTestCase {
self.prepareStack { (dataStack) in self.prepareStack { (dataStack) in
let groupBy = GroupBy("testString") let groupBy = GroupBy(#keyPath(TestEntity1.testString))
let request = NSFetchRequest<TestEntity1>() let request = NSFetchRequest<TestEntity1>()
_ = From<TestEntity1>().applyToFetchRequest(request, context: dataStack.mainContext) _ = From<TestEntity1>().applyToFetchRequest(request, context: dataStack.mainContext)

View File

@@ -45,12 +45,12 @@ class ImportTests: BaseTestDataTestCase {
let object = try transaction.importObject( let object = try transaction.importObject(
Into<TestEntity1>(), Into<TestEntity1>(),
source: [ source: [
"testBoolean": NSNumber(value: true), #keyPath(TestEntity1.testBoolean): NSNumber(value: true),
"testNumber": NSNumber(value: 1), #keyPath(TestEntity1.testNumber): NSNumber(value: 1),
"testDecimal": NSDecimalNumber(string: "1"), #keyPath(TestEntity1.testDecimal): NSDecimalNumber(string: "1"),
"testString": "nil:TestEntity1:1", #keyPath(TestEntity1.testString): "nil:TestEntity1:1",
"testData": ("nil:TestEntity1:1" as NSString).data(using: String.Encoding.utf8.rawValue)!, #keyPath(TestEntity1.testData): ("nil:TestEntity1:1" as NSString).data(using: String.Encoding.utf8.rawValue)!,
"testDate": self.dateFormatter.date(from: "2000-01-01T00:00:00Z")!, #keyPath(TestEntity1.testDate): self.dateFormatter.date(from: "2000-01-01T00:00:00Z")!,
"skip_insert": "" "skip_insert": ""
] ]
) )
@@ -78,12 +78,12 @@ class ImportTests: BaseTestDataTestCase {
let _ = try transaction.importObject( let _ = try transaction.importObject(
Into<TestEntity1>(), Into<TestEntity1>(),
source: [ source: [
"testBoolean": NSNumber(value: true), #keyPath(TestEntity1.testBoolean): NSNumber(value: true),
"testNumber": NSNumber(value: 1), #keyPath(TestEntity1.testNumber): NSNumber(value: 1),
"testDecimal": NSDecimalNumber(string: "1"), #keyPath(TestEntity1.testDecimal): NSDecimalNumber(string: "1"),
"testString": "nil:TestEntity1:1", #keyPath(TestEntity1.testString): "nil:TestEntity1:1",
"testData": ("nil:TestEntity1:1" as NSString).data(using: String.Encoding.utf8.rawValue)!, #keyPath(TestEntity1.testData): ("nil:TestEntity1:1" as NSString).data(using: String.Encoding.utf8.rawValue)!,
"testDate": self.dateFormatter.date(from: "2000-01-01T00:00:00Z")!, #keyPath(TestEntity1.testDate): self.dateFormatter.date(from: "2000-01-01T00:00:00Z")!,
"throw_on_insert": "" "throw_on_insert": ""
] ]
) )
@@ -126,12 +126,12 @@ class ImportTests: BaseTestDataTestCase {
let object = try transaction.importObject( let object = try transaction.importObject(
Into<TestEntity1>(), Into<TestEntity1>(),
source: [ source: [
"testBoolean": NSNumber(value: true), #keyPath(TestEntity1.testBoolean): NSNumber(value: true),
"testNumber": NSNumber(value: 1), #keyPath(TestEntity1.testNumber): NSNumber(value: 1),
"testDecimal": NSDecimalNumber(string: "1"), #keyPath(TestEntity1.testDecimal): NSDecimalNumber(string: "1"),
"testString": "nil:TestEntity1:1", #keyPath(TestEntity1.testString): "nil:TestEntity1:1",
"testData": ("nil:TestEntity1:1" as NSString).data(using: String.Encoding.utf8.rawValue)!, #keyPath(TestEntity1.testData): ("nil:TestEntity1:1" as NSString).data(using: String.Encoding.utf8.rawValue)!,
"testDate": self.dateFormatter.date(from: "2000-01-01T00:00:00Z")! #keyPath(TestEntity1.testDate): self.dateFormatter.date(from: "2000-01-01T00:00:00Z")!
] ]
) )
XCTAssertNotNil(object) XCTAssertNotNil(object)
@@ -147,12 +147,12 @@ class ImportTests: BaseTestDataTestCase {
try transaction.importObject( try transaction.importObject(
object!, object!,
source: [ source: [
"testBoolean": NSNumber(value: false), #keyPath(TestEntity1.testBoolean): NSNumber(value: false),
"testNumber": NSNumber(value: 2), #keyPath(TestEntity1.testNumber): NSNumber(value: 2),
"testDecimal": NSDecimalNumber(string: "2"), #keyPath(TestEntity1.testDecimal): NSDecimalNumber(string: "2"),
"testString": "nil:TestEntity1:2", #keyPath(TestEntity1.testString): "nil:TestEntity1:2",
"testData": ("nil:TestEntity1:2" as NSString).data(using: String.Encoding.utf8.rawValue)!, #keyPath(TestEntity1.testData): ("nil:TestEntity1:2" as NSString).data(using: String.Encoding.utf8.rawValue)!,
"testDate": self.dateFormatter.date(from: "2000-01-02T00:00:00Z")! #keyPath(TestEntity1.testDate): self.dateFormatter.date(from: "2000-01-02T00:00:00Z")!
] ]
) )
XCTAssertEqual(transaction.fetchCount(From<TestEntity1>()), 1) XCTAssertEqual(transaction.fetchCount(From<TestEntity1>()), 1)
@@ -184,21 +184,21 @@ class ImportTests: BaseTestDataTestCase {
let sourceArray: [TestEntity1.ImportSource] = [ let sourceArray: [TestEntity1.ImportSource] = [
[ [
"testBoolean": NSNumber(value: true), #keyPath(TestEntity1.testBoolean): NSNumber(value: true),
"testNumber": NSNumber(value: 1), #keyPath(TestEntity1.testNumber): NSNumber(value: 1),
"testDecimal": NSDecimalNumber(string: "1"), #keyPath(TestEntity1.testDecimal): NSDecimalNumber(string: "1"),
"testString": "nil:TestEntity1:1", #keyPath(TestEntity1.testString): "nil:TestEntity1:1",
"testData": ("nil:TestEntity1:1" as NSString).data(using: String.Encoding.utf8.rawValue)!, #keyPath(TestEntity1.testData): ("nil:TestEntity1:1" as NSString).data(using: String.Encoding.utf8.rawValue)!,
"testDate": self.dateFormatter.date(from: "2000-01-01T00:00:00Z")!, #keyPath(TestEntity1.testDate): self.dateFormatter.date(from: "2000-01-01T00:00:00Z")!,
"skip_insert": "" "skip_insert": ""
], ],
[ [
"testBoolean": NSNumber(value: false), #keyPath(TestEntity1.testBoolean): NSNumber(value: false),
"testNumber": NSNumber(value: 2), #keyPath(TestEntity1.testNumber): NSNumber(value: 2),
"testDecimal": NSDecimalNumber(string: "2"), #keyPath(TestEntity1.testDecimal): NSDecimalNumber(string: "2"),
"testString": "nil:TestEntity1:2", #keyPath(TestEntity1.testString): "nil:TestEntity1:2",
"testData": ("nil:TestEntity1:2" as NSString).data(using: String.Encoding.utf8.rawValue)!, #keyPath(TestEntity1.testData): ("nil:TestEntity1:2" as NSString).data(using: String.Encoding.utf8.rawValue)!,
"testDate": self.dateFormatter.date(from: "2000-01-02T00:00:00Z")! #keyPath(TestEntity1.testDate): self.dateFormatter.date(from: "2000-01-02T00:00:00Z")!
] ]
] ]
let objects = try transaction.importObjects( let objects = try transaction.importObjects(
@@ -211,12 +211,12 @@ class ImportTests: BaseTestDataTestCase {
let object = objects[0] let object = objects[0]
let dictionary = sourceArray[1] let dictionary = sourceArray[1]
XCTAssertNil(object.testEntityID) XCTAssertNil(object.testEntityID)
XCTAssertEqual(object.testBoolean, dictionary["testBoolean"] as? NSNumber) XCTAssertEqual(object.testBoolean, dictionary[(#keyPath(TestEntity1.testBoolean))] as? NSNumber)
XCTAssertEqual(object.testNumber, dictionary["testNumber"] as? NSNumber) XCTAssertEqual(object.testNumber, dictionary[(#keyPath(TestEntity1.testNumber))] as? NSNumber)
XCTAssertEqual(object.testDecimal, dictionary["testDecimal"] as? NSDecimalNumber) XCTAssertEqual(object.testDecimal, dictionary[(#keyPath(TestEntity1.testDecimal))] as? NSDecimalNumber)
XCTAssertEqual(object.testString, dictionary["testString"] as? String) XCTAssertEqual(object.testString, dictionary[(#keyPath(TestEntity1.testString))] as? String)
XCTAssertEqual(object.testData, dictionary["testData"] as? Data) XCTAssertEqual(object.testData, dictionary[(#keyPath(TestEntity1.testData))] as? Data)
XCTAssertEqual(object.testDate, dictionary["testDate"] as? Date) XCTAssertEqual(object.testDate, dictionary[(#keyPath(TestEntity1.testDate))] as? Date)
} }
catch { catch {
@@ -239,21 +239,21 @@ class ImportTests: BaseTestDataTestCase {
let sourceArray: [TestEntity1.ImportSource] = [ let sourceArray: [TestEntity1.ImportSource] = [
[ [
"testBoolean": NSNumber(value: true), #keyPath(TestEntity1.testBoolean): NSNumber(value: true),
"testNumber": NSNumber(value: 1), #keyPath(TestEntity1.testNumber): NSNumber(value: 1),
"testDecimal": NSDecimalNumber(string: "1"), #keyPath(TestEntity1.testDecimal): NSDecimalNumber(string: "1"),
"testString": "nil:TestEntity1:1", #keyPath(TestEntity1.testString): "nil:TestEntity1:1",
"testData": ("nil:TestEntity1:1" as NSString).data(using: String.Encoding.utf8.rawValue)!, #keyPath(TestEntity1.testData): ("nil:TestEntity1:1" as NSString).data(using: String.Encoding.utf8.rawValue)!,
"testDate": self.dateFormatter.date(from: "2000-01-01T00:00:00Z")!, #keyPath(TestEntity1.testDate): self.dateFormatter.date(from: "2000-01-01T00:00:00Z")!,
"throw_on_insert": "" "throw_on_insert": ""
], ],
[ [
"testBoolean": NSNumber(value: false), #keyPath(TestEntity1.testBoolean): NSNumber(value: false),
"testNumber": NSNumber(value: 2), #keyPath(TestEntity1.testNumber): NSNumber(value: 2),
"testDecimal": NSDecimalNumber(string: "2"), #keyPath(TestEntity1.testDecimal): NSDecimalNumber(string: "2"),
"testString": "nil:TestEntity1:2", #keyPath(TestEntity1.testString): "nil:TestEntity1:2",
"testData": ("nil:TestEntity1:2" as NSString).data(using: String.Encoding.utf8.rawValue)!, #keyPath(TestEntity1.testData): ("nil:TestEntity1:2" as NSString).data(using: String.Encoding.utf8.rawValue)!,
"testDate": self.dateFormatter.date(from: "2000-01-02T00:00:00Z")! #keyPath(TestEntity1.testDate): self.dateFormatter.date(from: "2000-01-02T00:00:00Z")!
] ]
] ]
let _ = try transaction.importObjects( let _ = try transaction.importObjects(
@@ -298,20 +298,20 @@ class ImportTests: BaseTestDataTestCase {
let sourceArray: [TestEntity1.ImportSource] = [ let sourceArray: [TestEntity1.ImportSource] = [
[ [
"testBoolean": NSNumber(value: true), #keyPath(TestEntity1.testBoolean): NSNumber(value: true),
"testNumber": NSNumber(value: 1), #keyPath(TestEntity1.testNumber): NSNumber(value: 1),
"testDecimal": NSDecimalNumber(string: "1"), #keyPath(TestEntity1.testDecimal): NSDecimalNumber(string: "1"),
"testString": "nil:TestEntity1:1", #keyPath(TestEntity1.testString): "nil:TestEntity1:1",
"testData": ("nil:TestEntity1:1" as NSString).data(using: String.Encoding.utf8.rawValue)!, #keyPath(TestEntity1.testData): ("nil:TestEntity1:1" as NSString).data(using: String.Encoding.utf8.rawValue)!,
"testDate": self.dateFormatter.date(from: "2000-01-01T00:00:00Z")! #keyPath(TestEntity1.testDate): self.dateFormatter.date(from: "2000-01-01T00:00:00Z")!
], ],
[ [
"testBoolean": NSNumber(value: false), #keyPath(TestEntity1.testBoolean): NSNumber(value: false),
"testNumber": NSNumber(value: 2), #keyPath(TestEntity1.testNumber): NSNumber(value: 2),
"testDecimal": NSDecimalNumber(string: "2"), #keyPath(TestEntity1.testDecimal): NSDecimalNumber(string: "2"),
"testString": "nil:TestEntity1:2", #keyPath(TestEntity1.testString): "nil:TestEntity1:2",
"testData": ("nil:TestEntity1:2" as NSString).data(using: String.Encoding.utf8.rawValue)!, #keyPath(TestEntity1.testData): ("nil:TestEntity1:2" as NSString).data(using: String.Encoding.utf8.rawValue)!,
"testDate": self.dateFormatter.date(from: "2000-01-02T00:00:00Z")! #keyPath(TestEntity1.testDate): self.dateFormatter.date(from: "2000-01-02T00:00:00Z")!
] ]
] ]
let objects = try transaction.importObjects( let objects = try transaction.importObjects(
@@ -327,12 +327,12 @@ class ImportTests: BaseTestDataTestCase {
let dictionary = sourceArray[i] let dictionary = sourceArray[i]
XCTAssertNil(object.testEntityID) XCTAssertNil(object.testEntityID)
XCTAssertEqual(object.testBoolean, dictionary["testBoolean"] as? NSNumber) XCTAssertEqual(object.testBoolean, dictionary[(#keyPath(TestEntity1.testBoolean))] as? NSNumber)
XCTAssertEqual(object.testNumber, dictionary["testNumber"] as? NSNumber) XCTAssertEqual(object.testNumber, dictionary[(#keyPath(TestEntity1.testNumber))] as? NSNumber)
XCTAssertEqual(object.testDecimal, dictionary["testDecimal"] as? NSDecimalNumber) XCTAssertEqual(object.testDecimal, dictionary[(#keyPath(TestEntity1.testDecimal))] as? NSDecimalNumber)
XCTAssertEqual(object.testString, dictionary["testString"] as? String) XCTAssertEqual(object.testString, dictionary[(#keyPath(TestEntity1.testString))] as? String)
XCTAssertEqual(object.testData, dictionary["testData"] as? Data) XCTAssertEqual(object.testData, dictionary[(#keyPath(TestEntity1.testData))] as? Data)
XCTAssertEqual(object.testDate, dictionary["testDate"] as? Date) XCTAssertEqual(object.testDate, dictionary[(#keyPath(TestEntity1.testDate))] as? Date)
} }
} }
catch { catch {
@@ -358,13 +358,13 @@ class ImportTests: BaseTestDataTestCase {
let object = try transaction.importUniqueObject( let object = try transaction.importUniqueObject(
Into<TestEntity1>(), Into<TestEntity1>(),
source: [ source: [
"testEntityID": NSNumber(value: 106), #keyPath(TestEntity1.testEntityID): NSNumber(value: 106),
"testBoolean": NSNumber(value: true), #keyPath(TestEntity1.testBoolean): NSNumber(value: true),
"testNumber": NSNumber(value: 6), #keyPath(TestEntity1.testNumber): NSNumber(value: 6),
"testDecimal": NSDecimalNumber(string: "6"), #keyPath(TestEntity1.testDecimal): NSDecimalNumber(string: "6"),
"testString": "nil:TestEntity1:6", #keyPath(TestEntity1.testString): "nil:TestEntity1:6",
"testData": ("nil:TestEntity1:6" as NSString).data(using: String.Encoding.utf8.rawValue)!, #keyPath(TestEntity1.testData): ("nil:TestEntity1:6" as NSString).data(using: String.Encoding.utf8.rawValue)!,
"testDate": self.dateFormatter.date(from: "2000-01-06T00:00:00Z")!, #keyPath(TestEntity1.testDate): self.dateFormatter.date(from: "2000-01-06T00:00:00Z")!,
"skip_insert": "" "skip_insert": ""
] ]
) )
@@ -380,20 +380,20 @@ class ImportTests: BaseTestDataTestCase {
let object = try transaction.importUniqueObject( let object = try transaction.importUniqueObject(
Into<TestEntity1>(), Into<TestEntity1>(),
source: [ source: [
"testEntityID": NSNumber(value: 105), #keyPath(TestEntity1.testEntityID): NSNumber(value: 105),
"testBoolean": NSNumber(value: false), #keyPath(TestEntity1.testBoolean): NSNumber(value: false),
"testNumber": NSNumber(value: 6), #keyPath(TestEntity1.testNumber): NSNumber(value: 6),
"testDecimal": NSDecimalNumber(string: "6"), #keyPath(TestEntity1.testDecimal): NSDecimalNumber(string: "6"),
"testString": "nil:TestEntity1:6", #keyPath(TestEntity1.testString): "nil:TestEntity1:6",
"testData": ("nil:TestEntity1:6" as NSString).data(using: String.Encoding.utf8.rawValue)!, #keyPath(TestEntity1.testData): ("nil:TestEntity1:6" as NSString).data(using: String.Encoding.utf8.rawValue)!,
"testDate": self.dateFormatter.date(from: "2000-01-06T00:00:00Z")!, #keyPath(TestEntity1.testDate): self.dateFormatter.date(from: "2000-01-06T00:00:00Z")!,
"skip_update": "" "skip_update": ""
] ]
) )
XCTAssertNil(object) XCTAssertNil(object)
XCTAssertEqual(transaction.fetchCount(From<TestEntity1>()), 5) XCTAssertEqual(transaction.fetchCount(From<TestEntity1>()), 5)
let existingObjects = transaction.fetchAll(From<TestEntity1>(), Where("testEntityID", isEqualTo: 105)) let existingObjects = transaction.fetchAll(From<TestEntity1>(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 105))
XCTAssertNotNil(existingObjects) XCTAssertNotNil(existingObjects)
XCTAssertEqual(existingObjects?.count, 1) XCTAssertEqual(existingObjects?.count, 1)
@@ -431,13 +431,13 @@ class ImportTests: BaseTestDataTestCase {
let _ = try transaction.importUniqueObject( let _ = try transaction.importUniqueObject(
Into<TestEntity1>(), Into<TestEntity1>(),
source: [ source: [
"testEntityID": NSNumber(value: 106), #keyPath(TestEntity1.testEntityID): NSNumber(value: 106),
"testBoolean": NSNumber(value: true), #keyPath(TestEntity1.testBoolean): NSNumber(value: true),
"testNumber": NSNumber(value: 6), #keyPath(TestEntity1.testNumber): NSNumber(value: 6),
"testDecimal": NSDecimalNumber(string: "6"), #keyPath(TestEntity1.testDecimal): NSDecimalNumber(string: "6"),
"testString": "nil:TestEntity1:6", #keyPath(TestEntity1.testString): "nil:TestEntity1:6",
"testData": ("nil:TestEntity1:6" as NSString).data(using: String.Encoding.utf8.rawValue)!, #keyPath(TestEntity1.testData): ("nil:TestEntity1:6" as NSString).data(using: String.Encoding.utf8.rawValue)!,
"testDate": self.dateFormatter.date(from: "2000-01-06T00:00:00Z")!, #keyPath(TestEntity1.testDate): self.dateFormatter.date(from: "2000-01-06T00:00:00Z")!,
"throw_on_insert": "" "throw_on_insert": ""
] ]
) )
@@ -448,7 +448,7 @@ class ImportTests: BaseTestDataTestCase {
errorExpectation.fulfill() errorExpectation.fulfill()
XCTAssertEqual(transaction.fetchCount(From<TestEntity1>()), 6) XCTAssertEqual(transaction.fetchCount(From<TestEntity1>()), 6)
let object = transaction.fetchOne(From<TestEntity1>(), Where("testEntityID", isEqualTo: 106)) let object = transaction.fetchOne(From<TestEntity1>(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 106))
XCTAssertNotNil(object) XCTAssertNotNil(object)
XCTAssertEqual(object?.testEntityID, NSNumber(value: 106)) XCTAssertEqual(object?.testEntityID, NSNumber(value: 106))
XCTAssertNil(object?.testBoolean) XCTAssertNil(object?.testBoolean)
@@ -472,13 +472,13 @@ class ImportTests: BaseTestDataTestCase {
let _ = try transaction.importUniqueObject( let _ = try transaction.importUniqueObject(
Into<TestEntity1>(), Into<TestEntity1>(),
source: [ source: [
"testEntityID": NSNumber(value: 105), #keyPath(TestEntity1.testEntityID): NSNumber(value: 105),
"testBoolean": NSNumber(value: false), #keyPath(TestEntity1.testBoolean): NSNumber(value: false),
"testNumber": NSNumber(value: 6), #keyPath(TestEntity1.testNumber): NSNumber(value: 6),
"testDecimal": NSDecimalNumber(string: "6"), #keyPath(TestEntity1.testDecimal): NSDecimalNumber(string: "6"),
"testString": "nil:TestEntity1:6", #keyPath(TestEntity1.testString): "nil:TestEntity1:6",
"testData": ("nil:TestEntity1:6" as NSString).data(using: String.Encoding.utf8.rawValue)!, #keyPath(TestEntity1.testData): ("nil:TestEntity1:6" as NSString).data(using: String.Encoding.utf8.rawValue)!,
"testDate": self.dateFormatter.date(from: "2000-01-06T00:00:00Z")!, #keyPath(TestEntity1.testDate): self.dateFormatter.date(from: "2000-01-06T00:00:00Z")!,
"throw_on_update": "" "throw_on_update": ""
] ]
) )
@@ -489,7 +489,7 @@ class ImportTests: BaseTestDataTestCase {
errorExpectation.fulfill() errorExpectation.fulfill()
XCTAssertEqual(transaction.fetchCount(From<TestEntity1>()), 6) XCTAssertEqual(transaction.fetchCount(From<TestEntity1>()), 6)
let existingObjects = transaction.fetchAll(From<TestEntity1>(), Where("testEntityID", isEqualTo: 105)) let existingObjects = transaction.fetchAll(From<TestEntity1>(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 105))
XCTAssertNotNil(existingObjects) XCTAssertNotNil(existingObjects)
XCTAssertEqual(existingObjects?.count, 1) XCTAssertEqual(existingObjects?.count, 1)
@@ -528,13 +528,13 @@ class ImportTests: BaseTestDataTestCase {
let object = try transaction.importUniqueObject( let object = try transaction.importUniqueObject(
Into<TestEntity1>(), Into<TestEntity1>(),
source: [ source: [
"testEntityID": NSNumber(value: 106), #keyPath(TestEntity1.testEntityID): NSNumber(value: 106),
"testBoolean": NSNumber(value: true), #keyPath(TestEntity1.testBoolean): NSNumber(value: true),
"testNumber": NSNumber(value: 6), #keyPath(TestEntity1.testNumber): NSNumber(value: 6),
"testDecimal": NSDecimalNumber(string: "6"), #keyPath(TestEntity1.testDecimal): NSDecimalNumber(string: "6"),
"testString": "nil:TestEntity1:6", #keyPath(TestEntity1.testString): "nil:TestEntity1:6",
"testData": ("nil:TestEntity1:6" as NSString).data(using: String.Encoding.utf8.rawValue)!, #keyPath(TestEntity1.testData): ("nil:TestEntity1:6" as NSString).data(using: String.Encoding.utf8.rawValue)!,
"testDate": self.dateFormatter.date(from: "2000-01-06T00:00:00Z")! #keyPath(TestEntity1.testDate): self.dateFormatter.date(from: "2000-01-06T00:00:00Z")!
] ]
) )
XCTAssertNotNil(object) XCTAssertNotNil(object)
@@ -557,13 +557,13 @@ class ImportTests: BaseTestDataTestCase {
let object = try transaction.importUniqueObject( let object = try transaction.importUniqueObject(
Into<TestEntity1>(), Into<TestEntity1>(),
source: [ source: [
"testEntityID": NSNumber(value: 106), #keyPath(TestEntity1.testEntityID): NSNumber(value: 106),
"testBoolean": NSNumber(value: false), #keyPath(TestEntity1.testBoolean): NSNumber(value: false),
"testNumber": NSNumber(value: 7), #keyPath(TestEntity1.testNumber): NSNumber(value: 7),
"testDecimal": NSDecimalNumber(string: "7"), #keyPath(TestEntity1.testDecimal): NSDecimalNumber(string: "7"),
"testString": "nil:TestEntity1:7", #keyPath(TestEntity1.testString): "nil:TestEntity1:7",
"testData": ("nil:TestEntity1:7" as NSString).data(using: String.Encoding.utf8.rawValue)!, #keyPath(TestEntity1.testData): ("nil:TestEntity1:7" as NSString).data(using: String.Encoding.utf8.rawValue)!,
"testDate": self.dateFormatter.date(from: "2000-01-07T00:00:00Z")!, #keyPath(TestEntity1.testDate): self.dateFormatter.date(from: "2000-01-07T00:00:00Z")!,
] ]
) )
XCTAssertNotNil(object) XCTAssertNotNil(object)
@@ -577,7 +577,7 @@ class ImportTests: BaseTestDataTestCase {
XCTAssertEqual(object?.testData, ("nil:TestEntity1:7" as NSString).data(using: String.Encoding.utf8.rawValue)!) XCTAssertEqual(object?.testData, ("nil:TestEntity1:7" as NSString).data(using: String.Encoding.utf8.rawValue)!)
XCTAssertEqual(object?.testDate, self.dateFormatter.date(from: "2000-01-07T00:00:00Z")!) XCTAssertEqual(object?.testDate, self.dateFormatter.date(from: "2000-01-07T00:00:00Z")!)
let existingObjects = transaction.fetchAll(From<TestEntity1>(), Where("testEntityID", isEqualTo: 106)) let existingObjects = transaction.fetchAll(From<TestEntity1>(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 106))
XCTAssertNotNil(existingObjects) XCTAssertNotNil(existingObjects)
XCTAssertEqual(existingObjects?.count, 1) XCTAssertEqual(existingObjects?.count, 1)
@@ -606,23 +606,23 @@ class ImportTests: BaseTestDataTestCase {
let sourceArray: [TestEntity1.ImportSource] = [ let sourceArray: [TestEntity1.ImportSource] = [
[ [
"testEntityID": NSNumber(value: 106), #keyPath(TestEntity1.testEntityID): NSNumber(value: 106),
"testBoolean": NSNumber(value: true), #keyPath(TestEntity1.testBoolean): NSNumber(value: true),
"testNumber": NSNumber(value: 6), #keyPath(TestEntity1.testNumber): NSNumber(value: 6),
"testDecimal": NSDecimalNumber(string: "6"), #keyPath(TestEntity1.testDecimal): NSDecimalNumber(string: "6"),
"testString": "nil:TestEntity1:6", #keyPath(TestEntity1.testString): "nil:TestEntity1:6",
"testData": ("nil:TestEntity1:6" as NSString).data(using: String.Encoding.utf8.rawValue)!, #keyPath(TestEntity1.testData): ("nil:TestEntity1:6" as NSString).data(using: String.Encoding.utf8.rawValue)!,
"testDate": self.dateFormatter.date(from: "2000-01-06T00:00:00Z")!, #keyPath(TestEntity1.testDate): self.dateFormatter.date(from: "2000-01-06T00:00:00Z")!,
"skip_insert": "" "skip_insert": ""
], ],
[ [
"testEntityID": NSNumber(value: 107), #keyPath(TestEntity1.testEntityID): NSNumber(value: 107),
"testBoolean": NSNumber(value: false), #keyPath(TestEntity1.testBoolean): NSNumber(value: false),
"testNumber": NSNumber(value: 7), #keyPath(TestEntity1.testNumber): NSNumber(value: 7),
"testDecimal": NSDecimalNumber(string: "7"), #keyPath(TestEntity1.testDecimal): NSDecimalNumber(string: "7"),
"testString": "nil:TestEntity1:7", #keyPath(TestEntity1.testString): "nil:TestEntity1:7",
"testData": ("nil:TestEntity1:7" as NSString).data(using: String.Encoding.utf8.rawValue)!, #keyPath(TestEntity1.testData): ("nil:TestEntity1:7" as NSString).data(using: String.Encoding.utf8.rawValue)!,
"testDate": self.dateFormatter.date(from: "2000-01-07T00:00:00Z")! #keyPath(TestEntity1.testDate): self.dateFormatter.date(from: "2000-01-07T00:00:00Z")!
] ]
] ]
let objects = try transaction.importUniqueObjects( let objects = try transaction.importUniqueObjects(
@@ -634,13 +634,13 @@ class ImportTests: BaseTestDataTestCase {
let object = objects[0] let object = objects[0]
let dictionary = sourceArray[1] let dictionary = sourceArray[1]
XCTAssertEqual(object.testEntityID, dictionary["testEntityID"] as? NSNumber) XCTAssertEqual(object.testEntityID, dictionary[(#keyPath(TestEntity1.testEntityID))] as? NSNumber)
XCTAssertEqual(object.testBoolean, dictionary["testBoolean"] as? NSNumber) XCTAssertEqual(object.testBoolean, dictionary[(#keyPath(TestEntity1.testBoolean))] as? NSNumber)
XCTAssertEqual(object.testNumber, dictionary["testNumber"] as? NSNumber) XCTAssertEqual(object.testNumber, dictionary[(#keyPath(TestEntity1.testNumber))] as? NSNumber)
XCTAssertEqual(object.testDecimal, dictionary["testDecimal"] as? NSDecimalNumber) XCTAssertEqual(object.testDecimal, dictionary[(#keyPath(TestEntity1.testDecimal))] as? NSDecimalNumber)
XCTAssertEqual(object.testString, dictionary["testString"] as? String) XCTAssertEqual(object.testString, dictionary[(#keyPath(TestEntity1.testString))] as? String)
XCTAssertEqual(object.testData, dictionary["testData"] as? Data) XCTAssertEqual(object.testData, dictionary[(#keyPath(TestEntity1.testData))] as? Data)
XCTAssertEqual(object.testDate, dictionary["testDate"] as? Date) XCTAssertEqual(object.testDate, dictionary[(#keyPath(TestEntity1.testDate))] as? Date)
} }
catch { catch {
@@ -665,23 +665,23 @@ class ImportTests: BaseTestDataTestCase {
let sourceArray: [TestEntity1.ImportSource] = [ let sourceArray: [TestEntity1.ImportSource] = [
[ [
"testEntityID": NSNumber(value: 106), #keyPath(TestEntity1.testEntityID): NSNumber(value: 106),
"testBoolean": NSNumber(value: true), #keyPath(TestEntity1.testBoolean): NSNumber(value: true),
"testNumber": NSNumber(value: 6), #keyPath(TestEntity1.testNumber): NSNumber(value: 6),
"testDecimal": NSDecimalNumber(string: "6"), #keyPath(TestEntity1.testDecimal): NSDecimalNumber(string: "6"),
"testString": "nil:TestEntity1:6", #keyPath(TestEntity1.testString): "nil:TestEntity1:6",
"testData": ("nil:TestEntity1:6" as NSString).data(using: String.Encoding.utf8.rawValue)!, #keyPath(TestEntity1.testData): ("nil:TestEntity1:6" as NSString).data(using: String.Encoding.utf8.rawValue)!,
"testDate": self.dateFormatter.date(from: "2000-01-06T00:00:00Z")!, #keyPath(TestEntity1.testDate): self.dateFormatter.date(from: "2000-01-06T00:00:00Z")!,
"throw_on_id": "" "throw_on_id": ""
], ],
[ [
"testEntityID": NSNumber(value: 107), #keyPath(TestEntity1.testEntityID): NSNumber(value: 107),
"testBoolean": NSNumber(value: false), #keyPath(TestEntity1.testBoolean): NSNumber(value: false),
"testNumber": NSNumber(value: 7), #keyPath(TestEntity1.testNumber): NSNumber(value: 7),
"testDecimal": NSDecimalNumber(string: "7"), #keyPath(TestEntity1.testDecimal): NSDecimalNumber(string: "7"),
"testString": "nil:TestEntity1:7", #keyPath(TestEntity1.testString): "nil:TestEntity1:7",
"testData": ("nil:TestEntity1:7" as NSString).data(using: String.Encoding.utf8.rawValue)!, #keyPath(TestEntity1.testData): ("nil:TestEntity1:7" as NSString).data(using: String.Encoding.utf8.rawValue)!,
"testDate": self.dateFormatter.date(from: "2000-01-07T00:00:00Z")! #keyPath(TestEntity1.testDate): self.dateFormatter.date(from: "2000-01-07T00:00:00Z")!
] ]
] ]
let _ = try transaction.importUniqueObjects( let _ = try transaction.importUniqueObjects(
@@ -695,8 +695,8 @@ class ImportTests: BaseTestDataTestCase {
errorExpectation.fulfill() errorExpectation.fulfill()
XCTAssertEqual(transaction.fetchCount(From<TestEntity1>()), 5) XCTAssertEqual(transaction.fetchCount(From<TestEntity1>()), 5)
XCTAssertNil(transaction.fetchOne(From<TestEntity1>(), Where("testEntityID", isEqualTo: 106))) XCTAssertNil(transaction.fetchOne(From<TestEntity1>(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 106)))
XCTAssertNil(transaction.fetchOne(From<TestEntity1>(), Where("testEntityID", isEqualTo: 107))) XCTAssertNil(transaction.fetchOne(From<TestEntity1>(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 107)))
} }
catch { catch {
@@ -712,23 +712,23 @@ class ImportTests: BaseTestDataTestCase {
let sourceArray: [TestEntity1.ImportSource] = [ let sourceArray: [TestEntity1.ImportSource] = [
[ [
"testEntityID": NSNumber(value: 106), #keyPath(TestEntity1.testEntityID): NSNumber(value: 106),
"testBoolean": NSNumber(value: true), #keyPath(TestEntity1.testBoolean): NSNumber(value: true),
"testNumber": NSNumber(value: 6), #keyPath(TestEntity1.testNumber): NSNumber(value: 6),
"testDecimal": NSDecimalNumber(string: "6"), #keyPath(TestEntity1.testDecimal): NSDecimalNumber(string: "6"),
"testString": "nil:TestEntity1:6", #keyPath(TestEntity1.testString): "nil:TestEntity1:6",
"testData": ("nil:TestEntity1:6" as NSString).data(using: String.Encoding.utf8.rawValue)!, #keyPath(TestEntity1.testData): ("nil:TestEntity1:6" as NSString).data(using: String.Encoding.utf8.rawValue)!,
"testDate": self.dateFormatter.date(from: "2000-01-06T00:00:00Z")!, #keyPath(TestEntity1.testDate): self.dateFormatter.date(from: "2000-01-06T00:00:00Z")!,
"throw_on_insert": "" "throw_on_insert": ""
], ],
[ [
"testEntityID": NSNumber(value: 107), #keyPath(TestEntity1.testEntityID): NSNumber(value: 107),
"testBoolean": NSNumber(value: false), #keyPath(TestEntity1.testBoolean): NSNumber(value: false),
"testNumber": NSNumber(value: 7), #keyPath(TestEntity1.testNumber): NSNumber(value: 7),
"testDecimal": NSDecimalNumber(string: "7"), #keyPath(TestEntity1.testDecimal): NSDecimalNumber(string: "7"),
"testString": "nil:TestEntity1:7", #keyPath(TestEntity1.testString): "nil:TestEntity1:7",
"testData": ("nil:TestEntity1:7" as NSString).data(using: String.Encoding.utf8.rawValue)!, #keyPath(TestEntity1.testData): ("nil:TestEntity1:7" as NSString).data(using: String.Encoding.utf8.rawValue)!,
"testDate": self.dateFormatter.date(from: "2000-01-07T00:00:00Z")! #keyPath(TestEntity1.testDate): self.dateFormatter.date(from: "2000-01-07T00:00:00Z")!
] ]
] ]
let _ = try transaction.importUniqueObjects( let _ = try transaction.importUniqueObjects(
@@ -741,7 +741,7 @@ class ImportTests: BaseTestDataTestCase {
errorExpectation.fulfill() errorExpectation.fulfill()
let object = transaction.fetchOne(From<TestEntity1>(), Where("testEntityID", isEqualTo: 106)) let object = transaction.fetchOne(From<TestEntity1>(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 106))
XCTAssertNotNil(object) XCTAssertNotNil(object)
XCTAssertEqual(object?.testEntityID, NSNumber(value: 106)) XCTAssertEqual(object?.testEntityID, NSNumber(value: 106))
XCTAssertNil(object?.testBoolean) XCTAssertNil(object?.testBoolean)
@@ -765,13 +765,13 @@ class ImportTests: BaseTestDataTestCase {
let sourceArray: [TestEntity1.ImportSource] = [ let sourceArray: [TestEntity1.ImportSource] = [
[ [
"testEntityID": NSNumber(value: 105), #keyPath(TestEntity1.testEntityID): NSNumber(value: 105),
"testBoolean": NSNumber(value: false), #keyPath(TestEntity1.testBoolean): NSNumber(value: false),
"testNumber": NSNumber(value: 6), #keyPath(TestEntity1.testNumber): NSNumber(value: 6),
"testDecimal": NSDecimalNumber(string: "6"), #keyPath(TestEntity1.testDecimal): NSDecimalNumber(string: "6"),
"testString": "nil:TestEntity1:6", #keyPath(TestEntity1.testString): "nil:TestEntity1:6",
"testData": ("nil:TestEntity1:6" as NSString).data(using: String.Encoding.utf8.rawValue)!, #keyPath(TestEntity1.testData): ("nil:TestEntity1:6" as NSString).data(using: String.Encoding.utf8.rawValue)!,
"testDate": self.dateFormatter.date(from: "2000-01-06T00:00:00Z")!, #keyPath(TestEntity1.testDate): self.dateFormatter.date(from: "2000-01-06T00:00:00Z")!,
"throw_on_update": "" "throw_on_update": ""
] ]
] ]
@@ -786,7 +786,7 @@ class ImportTests: BaseTestDataTestCase {
errorExpectation.fulfill() errorExpectation.fulfill()
XCTAssertEqual(transaction.fetchCount(From<TestEntity1>()), 5) XCTAssertEqual(transaction.fetchCount(From<TestEntity1>()), 5)
let object = transaction.fetchOne(From<TestEntity1>(), Where("testEntityID", isEqualTo: 105)) let object = transaction.fetchOne(From<TestEntity1>(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 105))
XCTAssertNotNil(object) XCTAssertNotNil(object)
XCTAssertEqual(object?.testEntityID, NSNumber(value: 105)) XCTAssertEqual(object?.testEntityID, NSNumber(value: 105))
XCTAssertEqual(object?.testBoolean, NSNumber(value: true)) XCTAssertEqual(object?.testBoolean, NSNumber(value: true))
@@ -796,7 +796,7 @@ class ImportTests: BaseTestDataTestCase {
XCTAssertEqual(object?.testData, ("nil:TestEntity1:5" as NSString).data(using: String.Encoding.utf8.rawValue)!) XCTAssertEqual(object?.testData, ("nil:TestEntity1:5" as NSString).data(using: String.Encoding.utf8.rawValue)!)
XCTAssertEqual(object?.testDate, self.dateFormatter.date(from: "2000-01-05T00:00:00Z")!) XCTAssertEqual(object?.testDate, self.dateFormatter.date(from: "2000-01-05T00:00:00Z")!)
let existingObjects = transaction.fetchAll(From<TestEntity1>(), Where("testEntityID", isEqualTo: 105)) let existingObjects = transaction.fetchAll(From<TestEntity1>(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 105))
XCTAssertNotNil(existingObjects) XCTAssertNotNil(existingObjects)
XCTAssertEqual(existingObjects?.count, 1) XCTAssertEqual(existingObjects?.count, 1)
@@ -826,22 +826,22 @@ class ImportTests: BaseTestDataTestCase {
let sourceArray: [TestEntity1.ImportSource] = [ let sourceArray: [TestEntity1.ImportSource] = [
[ [
"testEntityID": NSNumber(value: 105), #keyPath(TestEntity1.testEntityID): NSNumber(value: 105),
"testBoolean": NSNumber(value: false), #keyPath(TestEntity1.testBoolean): NSNumber(value: false),
"testNumber": NSNumber(value: 15), #keyPath(TestEntity1.testNumber): NSNumber(value: 15),
"testDecimal": NSDecimalNumber(string: "15"), #keyPath(TestEntity1.testDecimal): NSDecimalNumber(string: "15"),
"testString": "nil:TestEntity1:15", #keyPath(TestEntity1.testString): "nil:TestEntity1:15",
"testData": ("nil:TestEntity1:15" as NSString).data(using: String.Encoding.utf8.rawValue)!, #keyPath(TestEntity1.testData): ("nil:TestEntity1:15" as NSString).data(using: String.Encoding.utf8.rawValue)!,
"testDate": self.dateFormatter.date(from: "2000-01-15T00:00:00Z")! #keyPath(TestEntity1.testDate): self.dateFormatter.date(from: "2000-01-15T00:00:00Z")!
], ],
[ [
"testEntityID": NSNumber(value: 106), #keyPath(TestEntity1.testEntityID): NSNumber(value: 106),
"testBoolean": NSNumber(value: false), #keyPath(TestEntity1.testBoolean): NSNumber(value: false),
"testNumber": NSNumber(value: 6), #keyPath(TestEntity1.testNumber): NSNumber(value: 6),
"testDecimal": NSDecimalNumber(string: "6"), #keyPath(TestEntity1.testDecimal): NSDecimalNumber(string: "6"),
"testString": "nil:TestEntity1:6", #keyPath(TestEntity1.testString): "nil:TestEntity1:6",
"testData": ("nil:TestEntity1:6" as NSString).data(using: String.Encoding.utf8.rawValue)!, #keyPath(TestEntity1.testData): ("nil:TestEntity1:6" as NSString).data(using: String.Encoding.utf8.rawValue)!,
"testDate": self.dateFormatter.date(from: "2000-01-06T00:00:00Z")! #keyPath(TestEntity1.testDate): self.dateFormatter.date(from: "2000-01-06T00:00:00Z")!
] ]
] ]
let objects = try transaction.importUniqueObjects( let objects = try transaction.importUniqueObjects(
@@ -855,15 +855,15 @@ class ImportTests: BaseTestDataTestCase {
let object = objects[i] let object = objects[i]
let dictionary = sourceArray[i] let dictionary = sourceArray[i]
XCTAssertEqual(object.testEntityID, dictionary["testEntityID"] as? NSNumber) XCTAssertEqual(object.testEntityID, dictionary[(#keyPath(TestEntity1.testEntityID))] as? NSNumber)
XCTAssertEqual(object.testBoolean, dictionary["testBoolean"] as? NSNumber) XCTAssertEqual(object.testBoolean, dictionary[(#keyPath(TestEntity1.testBoolean))] as? NSNumber)
XCTAssertEqual(object.testNumber, dictionary["testNumber"] as? NSNumber) XCTAssertEqual(object.testNumber, dictionary[(#keyPath(TestEntity1.testNumber))] as? NSNumber)
XCTAssertEqual(object.testDecimal, dictionary["testDecimal"] as? NSDecimalNumber) XCTAssertEqual(object.testDecimal, dictionary[(#keyPath(TestEntity1.testDecimal))] as? NSDecimalNumber)
XCTAssertEqual(object.testString, dictionary["testString"] as? String) XCTAssertEqual(object.testString, dictionary[(#keyPath(TestEntity1.testString))] as? String)
XCTAssertEqual(object.testData, dictionary["testData"] as? Data) XCTAssertEqual(object.testData, dictionary[(#keyPath(TestEntity1.testData))] as? Data)
XCTAssertEqual(object.testDate, dictionary["testDate"] as? Date) XCTAssertEqual(object.testDate, dictionary[(#keyPath(TestEntity1.testDate))] as? Date)
} }
let existingObjects = transaction.fetchAll(From<TestEntity1>(), Where("testEntityID", isEqualTo: 105)) let existingObjects = transaction.fetchAll(From<TestEntity1>(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 105))
XCTAssertNotNil(existingObjects) XCTAssertNotNil(existingObjects)
XCTAssertEqual(existingObjects?.count, 1) XCTAssertEqual(existingObjects?.count, 1)
@@ -915,12 +915,12 @@ extension TestEntity1: ImportableUniqueObject {
throw TestInsertError() throw TestInsertError()
} }
self.testBoolean = source["testBoolean"] as? NSNumber self.testBoolean = source[(#keyPath(TestEntity1.testBoolean))] as? NSNumber
self.testNumber = source["testNumber"] as? NSNumber self.testNumber = source[(#keyPath(TestEntity1.testNumber))] as? NSNumber
self.testDecimal = source["testDecimal"] as? NSDecimalNumber self.testDecimal = source[(#keyPath(TestEntity1.testDecimal))] as? NSDecimalNumber
self.testString = source["testString"] as? String self.testString = source[(#keyPath(TestEntity1.testString))] as? String
self.testData = source["testData"] as? Data self.testData = source[(#keyPath(TestEntity1.testData))] as? Data
self.testDate = source["testDate"] as? Date self.testDate = source[(#keyPath(TestEntity1.testDate))] as? Date
self.testNil = nil self.testNil = nil
} }
@@ -931,7 +931,7 @@ extension TestEntity1: ImportableUniqueObject {
static var uniqueIDKeyPath: String { static var uniqueIDKeyPath: String {
return "testEntityID" return #keyPath(TestEntity1.testEntityID)
} }
var uniqueIDValue: NSNumber { var uniqueIDValue: NSNumber {
@@ -962,7 +962,7 @@ extension TestEntity1: ImportableUniqueObject {
throw TestIDError() throw TestIDError()
} }
return source["testEntityID"] as? NSNumber return source[(#keyPath(TestEntity1.testEntityID))] as? NSNumber
} }
func updateFromImportSource(_ source: ImportSource, inTransaction transaction: BaseDataTransaction) throws { func updateFromImportSource(_ source: ImportSource, inTransaction transaction: BaseDataTransaction) throws {
@@ -971,12 +971,12 @@ extension TestEntity1: ImportableUniqueObject {
throw TestUpdateError() throw TestUpdateError()
} }
self.testBoolean = source["testBoolean"] as? NSNumber self.testBoolean = source[(#keyPath(TestEntity1.testBoolean))] as? NSNumber
self.testNumber = source["testNumber"] as? NSNumber self.testNumber = source[(#keyPath(TestEntity1.testNumber))] as? NSNumber
self.testDecimal = source["testDecimal"] as? NSDecimalNumber self.testDecimal = source[(#keyPath(TestEntity1.testDecimal))] as? NSDecimalNumber
self.testString = source["testString"] as? String self.testString = source[(#keyPath(TestEntity1.testString))] as? String
self.testData = source["testData"] as? Data self.testData = source[(#keyPath(TestEntity1.testData))] as? Data
self.testDate = source["testDate"] as? Date self.testDate = source[(#keyPath(TestEntity1.testDate))] as? Date
self.testNil = nil self.testNil = nil
} }
} }

View File

@@ -43,8 +43,8 @@ class ListObserverTests: BaseTestDataTestCase {
let observer = TestListObserver() let observer = TestListObserver()
let monitor = stack.monitorSectionedList( let monitor = stack.monitorSectionedList(
From<TestEntity1>(), From<TestEntity1>(),
SectionBy("testBoolean"), SectionBy(#keyPath(TestEntity1.testBoolean)),
OrderBy(.ascending("testBoolean"), .ascending("testEntityID")) OrderBy(.ascending(#keyPath(TestEntity1.testBoolean)), .ascending(#keyPath(TestEntity1.testEntityID)))
) )
monitor.addObserver(observer) monitor.addObserver(observer)
@@ -171,8 +171,8 @@ class ListObserverTests: BaseTestDataTestCase {
let observer = TestListObserver() let observer = TestListObserver()
let monitor = stack.monitorSectionedList( let monitor = stack.monitorSectionedList(
From<TestEntity1>(), From<TestEntity1>(),
SectionBy("testBoolean"), SectionBy(#keyPath(TestEntity1.testBoolean)),
OrderBy(.ascending("testBoolean"), .ascending("testEntityID")) OrderBy(.ascending(#keyPath(TestEntity1.testBoolean)), .ascending(#keyPath(TestEntity1.testEntityID)))
) )
monitor.addObserver(observer) monitor.addObserver(observer)
@@ -272,7 +272,7 @@ class ListObserverTests: BaseTestDataTestCase {
if let object = transaction.fetchOne( if let object = transaction.fetchOne(
From<TestEntity1>(), From<TestEntity1>(),
Where("testEntityID", isEqualTo: 101)) { Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 101)) {
object.testNumber = NSNumber(value: 11) object.testNumber = NSNumber(value: 11)
object.testDecimal = NSDecimalNumber(string: "11") object.testDecimal = NSDecimalNumber(string: "11")
@@ -286,7 +286,7 @@ class ListObserverTests: BaseTestDataTestCase {
} }
if let object = transaction.fetchOne( if let object = transaction.fetchOne(
From<TestEntity1>(), From<TestEntity1>(),
Where("testEntityID", isEqualTo: 102)) { Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 102)) {
object.testNumber = NSNumber(value: 22) object.testNumber = NSNumber(value: 22)
object.testDecimal = NSDecimalNumber(string: "22") object.testDecimal = NSDecimalNumber(string: "22")
@@ -325,8 +325,8 @@ class ListObserverTests: BaseTestDataTestCase {
let observer = TestListObserver() let observer = TestListObserver()
let monitor = stack.monitorSectionedList( let monitor = stack.monitorSectionedList(
From<TestEntity1>(), From<TestEntity1>(),
SectionBy("testBoolean"), SectionBy(#keyPath(TestEntity1.testBoolean)),
OrderBy(.ascending("testBoolean"), .ascending("testEntityID")) OrderBy(.ascending(#keyPath(TestEntity1.testBoolean)), .ascending(#keyPath(TestEntity1.testEntityID)))
) )
monitor.addObserver(observer) monitor.addObserver(observer)
@@ -398,7 +398,7 @@ class ListObserverTests: BaseTestDataTestCase {
if let object = transaction.fetchOne( if let object = transaction.fetchOne(
From<TestEntity1>(), From<TestEntity1>(),
Where("testEntityID", isEqualTo: 102)) { Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 102)) {
object.testBoolean = NSNumber(value: true) object.testBoolean = NSNumber(value: true)
} }
@@ -433,8 +433,8 @@ class ListObserverTests: BaseTestDataTestCase {
let observer = TestListObserver() let observer = TestListObserver()
let monitor = stack.monitorSectionedList( let monitor = stack.monitorSectionedList(
From<TestEntity1>(), From<TestEntity1>(),
SectionBy("testBoolean"), SectionBy(#keyPath(TestEntity1.testBoolean)),
OrderBy(.ascending("testBoolean"), .ascending("testEntityID")) OrderBy(.ascending(#keyPath(TestEntity1.testBoolean)), .ascending(#keyPath(TestEntity1.testEntityID)))
) )
monitor.addObserver(observer) monitor.addObserver(observer)
@@ -533,7 +533,7 @@ class ListObserverTests: BaseTestDataTestCase {
transaction.deleteAll( transaction.deleteAll(
From<TestEntity1>(), From<TestEntity1>(),
Where("testBoolean", isEqualTo: false) Where(#keyPath(TestEntity1.testBoolean), isEqualTo: false)
) )
transaction.commit { (result) in transaction.commit { (result) in

View File

@@ -44,7 +44,7 @@ class ObjectObserverTests: BaseTestDataTestCase {
guard let object = stack.fetchOne( guard let object = stack.fetchOne(
From<TestEntity1>(), From<TestEntity1>(),
Where("testEntityID", isEqualTo: 101)) else { Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 101)) else {
XCTFail() XCTFail()
return return
@@ -87,8 +87,8 @@ class ObjectObserverTests: BaseTestDataTestCase {
"object": object, "object": object,
"changedPersistentKeys": Set( "changedPersistentKeys": Set(
[ [
"testNumber", #keyPath(TestEntity1.testNumber),
"testString" #keyPath(TestEntity1.testString)
] ]
) )
] as NSDictionary ] as NSDictionary
@@ -141,7 +141,7 @@ class ObjectObserverTests: BaseTestDataTestCase {
guard let object = stack.fetchOne( guard let object = stack.fetchOne(
From<TestEntity1>(), From<TestEntity1>(),
Where("testEntityID", isEqualTo: 101)) else { Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 101)) else {
XCTFail() XCTFail()
return return

File diff suppressed because it is too large Load Diff

View File

@@ -32,7 +32,7 @@ import CoreData
/** /**
All errors thrown from CoreStore are expressed in `CoreStoreError` enum values. All errors thrown from CoreStore are expressed in `CoreStoreError` enum values.
*/ */
public enum CoreStoreError: Error, Hashable { public enum CoreStoreError: Error, CustomNSError, Hashable {
/** /**
A failure occured because of an unknown error. A failure occured because of an unknown error.
@@ -60,14 +60,14 @@ public enum CoreStoreError: Error, Hashable {
case internalError(NSError: NSError) case internalError(NSError: NSError)
// MARK: ErrorType // MARK: CustomNSError
public var _domain: String { public static var errorDomain: String {
return CoreStoreErrorDomain return CoreStoreErrorDomain
} }
public var _code: Int { public var errorCode: Int {
switch self { switch self {
@@ -88,6 +88,37 @@ public enum CoreStoreError: Error, Hashable {
} }
} }
public var errorUserInfo: [String : Any] {
switch self {
case .unknown:
return [:]
case .differentStorageExistsAtURL(let existingPersistentStoreURL):
return [
"existingPersistentStoreURL": existingPersistentStoreURL
]
case .mappingModelNotFound(let localStoreURL, let targetModel, let targetModelVersion):
return [
"localStoreURL": localStoreURL,
"targetModel": targetModel,
"targetModelVersion": targetModelVersion
]
case .progressiveMigrationRequired(let localStoreURL):
return [
"localStoreURL": localStoreURL
]
case .internalError(let NSError):
return [
"NSError": NSError
]
}
}
// MARK: Hashable // MARK: Hashable

View File

@@ -322,13 +322,14 @@ public func == (lhs: SelectTerm, rhs: SelectTerm) -> Bool {
- `Double` - `Double`
- `Float` - `Float`
- `String` - `String`
- `Date`
- `Data`
- `NSNumber` - `NSNumber`
- `NSString` - `NSString`
- `NSDecimalNumber` - `NSDecimalNumber`
- `NSDate` - `NSDate`
- `NSData` - `NSData`
- `NSManagedObjectID` - `NSManagedObjectID`
- `NSString`
- for `queryAttributes(...)` methods: - for `queryAttributes(...)` methods:
- `NSDictionary` - `NSDictionary`

View File

@@ -65,6 +65,6 @@ public struct Tweak: FetchClause, QueryClause, DeleteClause {
public func applyToFetchRequest<ResultType: NSFetchRequestResult>(_ fetchRequest: NSFetchRequest<ResultType>) { public func applyToFetchRequest<ResultType: NSFetchRequestResult>(_ fetchRequest: NSFetchRequest<ResultType>) {
self.closure(unsafeBitCast(fetchRequest, to: NSFetchRequest<NSFetchRequestResult>.self)) self.closure(fetchRequest as! NSFetchRequest<NSFetchRequestResult>)
} }
} }

View File

@@ -55,7 +55,7 @@ internal final class CoreStoreFetchedResultsController: NSFetchedResultsControll
context: context, context: context,
applyAffectedStores: false applyAffectedStores: false
) )
applyFetchClauses(unsafeBitCast(fetchRequest, to: NSFetchRequest<NSManagedObject>.self)) applyFetchClauses(fetchRequest)
if let from = from { if let from = from {

View File

@@ -82,7 +82,7 @@ public protocol CoreStoreLogger {
/** /**
Handles fatal errors made throughout the `CoreStore` framework. The app wil terminate after this method is called. Handles fatal errors made throughout the `CoreStore` framework. The app wil terminate after this method is called.
- Important: Implementers may guarantee that the function doesn't return, either by calling another `@noreturn` function such as `fatalError()` or `abort()`, or by raising an exception. If the implementation does not terminate the app, CoreStore will call an internal `fatalError()` to do so. - Important: Implementers may guarantee that the function doesn't return, either by calling another `Never` function such as `fatalError()` or `abort()`, or by raising an exception. If the implementation does not terminate the app, CoreStore will call an internal `fatalError()` to do so.
- parameter message: the fatal error message - parameter message: the fatal error message
- parameter fileName: the source file name - parameter fileName: the source file name

View File

@@ -113,7 +113,7 @@ public final class DefaultLogger: CoreStoreLogger {
/** /**
Handles fatal errors made throughout the `CoreStore` framework. Handles fatal errors made throughout the `CoreStore` framework.
- Important: This method should be marked `@noreturn` and implementers should guarantee that the function doesn't, either by calling another `@noreturn` function such as `fatalError()` or `abort()`, or by raising an exception. - Important: Implementers should guarantee that this function doesn't return, either by calling another `Never` function such as `fatalError()` or `abort()`, or by raising an exception.
- parameter message: the fatal error message - parameter message: the fatal error message
- parameter fileName: the source file name - parameter fileName: the source file name

View File

@@ -74,7 +74,7 @@ public extension CSDataStack {
sectionBy: nil, sectionBy: nil,
applyFetchClauses: { (fetchRequest) in applyFetchClauses: { (fetchRequest) in
fetchClauses.forEach { $0.applyToFetchRequest(unsafeBitCast(fetchRequest, to: NSFetchRequest<NSFetchRequestResult>.self)) } fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest as! NSFetchRequest<NSFetchRequestResult>) }
} }
) )
} }
@@ -104,7 +104,7 @@ public extension CSDataStack {
sectionBy: nil, sectionBy: nil,
applyFetchClauses: { (fetchRequest) in applyFetchClauses: { (fetchRequest) in
fetchClauses.forEach { $0.applyToFetchRequest(unsafeBitCast(fetchRequest, to: NSFetchRequest<NSFetchRequestResult>.self)) } fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest as! NSFetchRequest<NSFetchRequestResult>) }
}, },
createAsynchronously: { createAsynchronously: {
@@ -140,7 +140,7 @@ public extension CSDataStack {
sectionBy: sectionBy.bridgeToSwift, sectionBy: sectionBy.bridgeToSwift,
applyFetchClauses: { (fetchRequest) in applyFetchClauses: { (fetchRequest) in
fetchClauses.forEach { $0.applyToFetchRequest(unsafeBitCast(fetchRequest, to: NSFetchRequest<NSFetchRequestResult>.self)) } fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest as! NSFetchRequest<NSFetchRequestResult>) }
} }
) )
} }
@@ -170,7 +170,7 @@ public extension CSDataStack {
sectionBy: sectionBy.bridgeToSwift, sectionBy: sectionBy.bridgeToSwift,
applyFetchClauses: { (fetchRequest) in applyFetchClauses: { (fetchRequest) in
fetchClauses.forEach { $0.applyToFetchRequest(unsafeBitCast(fetchRequest, to: NSFetchRequest<NSFetchRequestResult>.self)) } fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest as! NSFetchRequest<NSFetchRequestResult>) }
}, },
createAsynchronously: { createAsynchronously: {

View File

@@ -76,58 +76,7 @@ public final class CSError: NSError, CoreStoreObjectiveCType {
return swift return swift
} }
let swift = CoreStoreError(_bridgedNSError: self) ?? .unknown
func createSwiftObject(_ error: CSError) -> CoreStoreError {
guard error.domain == CoreStoreErrorDomain else {
return .internalError(NSError: self)
}
guard let code = CoreStoreErrorCode(rawValue: error.code) else {
return .unknown
}
let info = error.userInfo
switch code {
case .unknownError:
return .unknown
case .differentStorageExistsAtURL:
guard case let existingPersistentStoreURL as URL = info["existingPersistentStoreURL"] else {
return .unknown
}
return .differentStorageExistsAtURL(existingPersistentStoreURL: existingPersistentStoreURL)
case .mappingModelNotFound:
guard let localStoreURL = info["localStoreURL"] as? URL,
let targetModel = info["targetModel"] as? NSManagedObjectModel,
let targetModelVersion = info["targetModelVersion"] as? String else {
return .unknown
}
return .mappingModelNotFound(localStoreURL: localStoreURL, targetModel: targetModel, targetModelVersion: targetModelVersion)
case .progressiveMigrationRequired:
guard let localStoreURL = info["localStoreURL"] as? URL else {
return .unknown
}
return .progressiveMigrationRequired(localStoreURL: localStoreURL)
case .internalError:
guard case let NSError as NSError = info["NSError"] else {
return .unknown
}
return .internalError(NSError: NSError)
}
}
let swift = createSwiftObject(self)
self.swiftError = swift self.swiftError = swift
return swift return swift
} }
@@ -138,43 +87,7 @@ public final class CSError: NSError, CoreStoreObjectiveCType {
public init(_ swiftValue: CoreStoreError) { public init(_ swiftValue: CoreStoreError) {
self.swiftError = swiftValue self.swiftError = swiftValue
super.init(domain: CoreStoreError.errorDomain, code: swiftValue.errorCode, userInfo: swiftValue.errorUserInfo)
let code: CoreStoreErrorCode
let info: [AnyHashable: Any]
switch swiftValue {
case .unknown:
code = .unknownError
info = [:]
case .differentStorageExistsAtURL(let existingPersistentStoreURL):
code = .differentStorageExistsAtURL
info = [
"existingPersistentStoreURL": existingPersistentStoreURL
]
case .mappingModelNotFound(let localStoreURL, let targetModel, let targetModelVersion):
code = .mappingModelNotFound
info = [
"localStoreURL": localStoreURL,
"targetModel": targetModel,
"targetModelVersion": targetModelVersion
]
case .progressiveMigrationRequired(let localStoreURL):
code = .progressiveMigrationRequired
info = [
"localStoreURL": localStoreURL
]
case .internalError(let NSError):
code = .internalError
info = [
"NSError": NSError
]
}
super.init(domain: CoreStoreErrorDomain, code: code.rawValue, userInfo: info)
} }
public required init?(coder aDecoder: NSCoder) { public required init?(coder aDecoder: NSCoder) {
@@ -229,7 +142,7 @@ public enum CSErrorCode: Int {
// MARK: - CoreStoreError // MARK: - CoreStoreError
extension CoreStoreError: CoreStoreSwiftType { extension CoreStoreError: CoreStoreSwiftType, _ObjectiveCBridgeableError {
// MARK: CoreStoreSwiftType // MARK: CoreStoreSwiftType
@@ -237,6 +150,73 @@ extension CoreStoreError: CoreStoreSwiftType {
return CSError(self) return CSError(self)
} }
// MARK: _ObjectiveCBridgeableError
public init?(_bridgedNSError error: NSError) {
guard error.domain == CoreStoreErrorDomain else {
if error is CSError {
self = .internalError(NSError: error)
return
}
return nil
}
guard let code = CoreStoreErrorCode(rawValue: error.code) else {
if error is CSError {
self = .unknown
return
}
return nil
}
let info = error.userInfo
switch code {
case .unknownError:
self = .unknown
case .differentStorageExistsAtURL:
guard case let existingPersistentStoreURL as URL = info["existingPersistentStoreURL"] else {
self = .unknown
return
}
self = .differentStorageExistsAtURL(existingPersistentStoreURL: existingPersistentStoreURL)
case .mappingModelNotFound:
guard let localStoreURL = info["localStoreURL"] as? URL,
let targetModel = info["targetModel"] as? NSManagedObjectModel,
let targetModelVersion = info["targetModelVersion"] as? String else {
self = .unknown
return
}
self = .mappingModelNotFound(localStoreURL: localStoreURL, targetModel: targetModel, targetModelVersion: targetModelVersion)
case .progressiveMigrationRequired:
guard let localStoreURL = info["localStoreURL"] as? URL else {
self = .unknown
return
}
self = .progressiveMigrationRequired(localStoreURL: localStoreURL)
case .internalError:
guard case let NSError as NSError = info["NSError"] else {
self = .unknown
return
}
self = .internalError(NSError: NSError)
}
}
} }

View File

@@ -503,7 +503,7 @@ public final class CSListMonitor: NSObject, CoreStoreObjectiveCType {
self.bridgeToSwift.refetch { (fetchRequest) in self.bridgeToSwift.refetch { (fetchRequest) in
fetchClauses.forEach { $0.applyToFetchRequest(unsafeBitCast(fetchRequest, to: NSFetchRequest<NSFetchRequestResult>.self)) } fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest as! NSFetchRequest<NSFetchRequestResult>) }
} }
} }

View File

@@ -99,11 +99,11 @@ public extension CoreStore {
} }
/** /**
Creates a `LocalStorageface` of the specified store type with default values and adds it to the `defaultStack`. This method blocks until completion. Creates a `LocalStorageInterface` of the specified store type with default values and adds it to the `defaultStack`. This method blocks until completion.
``` ```
try CoreStore.addStorageAndWait(SQLiteStore.self) try CoreStore.addStorageAndWait(SQLiteStore.self)
``` ```
- parameter storeType: the `LocalStorageface` type - parameter storeType: the `LocalStorageInterface` type
- throws: a `CoreStoreError` value indicating the failure - throws: a `CoreStoreError` value indicating the failure
- returns: the local storage added to the `defaultStack` - returns: the local storage added to the `defaultStack`
*/ */

View File

@@ -177,11 +177,11 @@ public final class DataStack {
} }
/** /**
Creates a `LocalStorageface` of the specified store type with default values and adds it to the stack. This method blocks until completion. Creates a `LocalStorageInterface` of the specified store type with default values and adds it to the stack. This method blocks until completion.
``` ```
try dataStack.addStorageAndWait(SQLiteStore.self) try dataStack.addStorageAndWait(SQLiteStore.self)
``` ```
- parameter storeType: the `LocalStorageface` type - parameter storeType: the `LocalStorageInterface` type
- throws: a `CoreStoreError` value indicating the failure - throws: a `CoreStoreError` value indicating the failure
- returns: the local storage added to the stack - returns: the local storage added to the stack
*/ */
@@ -424,36 +424,33 @@ public final class DataStack {
internal func persistentStoreForEntityClass(_ entityClass: AnyClass, configuration: String?, inferStoreIfPossible: Bool) -> (store: NSPersistentStore?, isAmbiguous: Bool) { internal func persistentStoreForEntityClass(_ entityClass: AnyClass, configuration: String?, inferStoreIfPossible: Bool) -> (store: NSPersistentStore?, isAmbiguous: Bool) {
var returnValue: (store: NSPersistentStore?, isAmbiguous: Bool) = (store: nil, isAmbiguous: false) return self.storeMetadataUpdateQueue.sync(flags: .barrier) { () -> (store: NSPersistentStore?, isAmbiguous: Bool) in
self.storeMetadataUpdateQueue.sync(flags: .barrier) {
let configurationsForEntity = self.entityConfigurationsMapping[NSStringFromClass(entityClass)] ?? [] let configurationsForEntity = self.entityConfigurationsMapping[NSStringFromClass(entityClass)] ?? []
if let configuration = configuration { if let configuration = configuration {
if configurationsForEntity.contains(configuration) { if configurationsForEntity.contains(configuration) {
returnValue = (store: self.configurationStoreMapping[configuration], isAmbiguous: false) return (store: self.configurationStoreMapping[configuration], isAmbiguous: false)
return
} }
else if !inferStoreIfPossible { else if !inferStoreIfPossible {
return return (store: nil, isAmbiguous: false)
} }
} }
switch configurationsForEntity.count { switch configurationsForEntity.count {
case 0: case 0:
return return (store: nil, isAmbiguous: false)
case 1 where inferStoreIfPossible: case 1 where inferStoreIfPossible:
returnValue = (store: self.configurationStoreMapping[configurationsForEntity.first!], isAmbiguous: false) return (store: self.configurationStoreMapping[configurationsForEntity.first!], isAmbiguous: false)
default: default:
returnValue = (store: nil, isAmbiguous: true) return (store: nil, isAmbiguous: true)
} }
} }
return returnValue
} }
internal func createPersistentStoreFromStorage(_ storage: StorageInterface, finalURL: URL?, finalStoreOptions: [AnyHashable: Any]?) throws -> NSPersistentStore { internal func createPersistentStoreFromStorage(_ storage: StorageInterface, finalURL: URL?, finalStoreOptions: [AnyHashable: Any]?) throws -> NSPersistentStore {

View File

@@ -34,7 +34,7 @@ import CoreData
/** /**
A storage interface backed by an SQLite database managed by iCloud. A storage interface backed by an SQLite database managed by iCloud.
*/ */
public class ICloudStore: CloudStorage { public final class ICloudStore: CloudStorage {
/** /**
Initializes an iCloud store interface from the given ubiquitous store information. Returns `nil` if the container could not be located or if iCloud storage is unavailable for the current user or device Initializes an iCloud store interface from the given ubiquitous store information. Returns `nil` if the container could not be located or if iCloud storage is unavailable for the current user or device

View File

@@ -454,8 +454,6 @@ public /*abstract*/ class BaseDataTransaction {
internal let childTransactionQueue = DispatchQueue.serial("com.corestore.datastack.childtransactionqueue") internal let childTransactionQueue = DispatchQueue.serial("com.corestore.datastack.childtransactionqueue")
internal let supportsUndo: Bool internal let supportsUndo: Bool
internal let bypassesQueueing: Bool internal let bypassesQueueing: Bool
internal var isCommitted = false internal var isCommitted = false
internal var result: SaveResult? internal var result: SaveResult?