mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-05-17 13:17:02 +02:00
Merge branch 'develop'
# Conflicts: # CoreStore.podspec # Sources/Info.plist
This commit is contained in:
+1
-1
@@ -1 +1 @@
|
|||||||
3.1
|
3.2
|
||||||
|
|||||||
+21
-16
@@ -1,5 +1,5 @@
|
|||||||
language: objective-c
|
language: objective-c
|
||||||
osx_image: xcode8.3
|
osx_image: xcode9
|
||||||
sudo: false
|
sudo: false
|
||||||
git:
|
git:
|
||||||
submodules: false
|
submodules: false
|
||||||
@@ -10,24 +10,29 @@ env:
|
|||||||
- LC_CTYPE=en_US.UTF-8
|
- LC_CTYPE=en_US.UTF-8
|
||||||
- LANG=en_US.UTF-8
|
- LANG=en_US.UTF-8
|
||||||
matrix:
|
matrix:
|
||||||
- DESTINATION="OS=10.3,name=iPhone 7" SCHEME="CoreStore iOS" SDK=iphonesimulator10.3 RUN_TESTS="YES" POD_LINT="NO"
|
- DESTINATION="OS=11.0,name=iPhone 8" SCHEME="CoreStore iOS" SDK=iphonesimulator11.0 RUN_TESTS="YES" POD_LINT="NO"
|
||||||
- DESTINATION="OS=10.1,name=iPhone 7" SCHEME="CoreStore iOS" SDK=iphonesimulator10.3 RUN_TESTS="YES" POD_LINT="NO"
|
- DESTINATION="OS=10.3,name=iPhone 7" SCHEME="CoreStore iOS" SDK=iphonesimulator11.0 RUN_TESTS="YES" POD_LINT="NO"
|
||||||
- DESTINATION="OS=9.0,name=iPhone 6 Plus" SCHEME="CoreStore iOS" SDK=iphonesimulator10.3 RUN_TESTS="YES" POD_LINT="NO"
|
- DESTINATION="OS=10.1,name=iPhone 7" SCHEME="CoreStore iOS" SDK=iphonesimulator11.0 RUN_TESTS="YES" POD_LINT="NO"
|
||||||
- DESTINATION="OS=8.4,name=iPhone 6" SCHEME="CoreStore iOS" SDK=iphonesimulator10.3 RUN_TESTS="YES" POD_LINT="NO"
|
- DESTINATION="OS=9.0,name=iPhone 6 Plus" SCHEME="CoreStore iOS" SDK=iphonesimulator11.0 RUN_TESTS="YES" POD_LINT="NO"
|
||||||
- DESTINATION="OS=8.3,name=iPhone 5S" SCHEME="CoreStore iOS" SDK=iphonesimulator10.3 RUN_TESTS="YES" POD_LINT="NO"
|
- DESTINATION="OS=8.4,name=iPhone 6" SCHEME="CoreStore iOS" SDK=iphonesimulator11.0 RUN_TESTS="YES" POD_LINT="NO"
|
||||||
- DESTINATION="OS=8.3,name=iPhone 5" SCHEME="CoreStore iOS" SDK=iphonesimulator10.3 RUN_TESTS="YES" POD_LINT="NO"
|
- DESTINATION="OS=8.3,name=iPhone 5S" SCHEME="CoreStore iOS" SDK=iphonesimulator11.0 RUN_TESTS="YES" POD_LINT="NO"
|
||||||
- DESTINATION="OS=8.3,name=iPhone 4S" SCHEME="CoreStore iOS" SDK=iphonesimulator10.3 RUN_TESTS="YES" POD_LINT="NO"
|
- DESTINATION="OS=8.3,name=iPhone 5" SCHEME="CoreStore iOS" SDK=iphonesimulator11.0 RUN_TESTS="YES" POD_LINT="NO"
|
||||||
- DESTINATION="arch=x86_64" SCHEME="CoreStore OSX" SDK=macosx10.12 RUN_TESTS="YES" POD_LINT="NO"
|
- DESTINATION="OS=8.3,name=iPhone 4S" SCHEME="CoreStore iOS" SDK=iphonesimulator11.0 RUN_TESTS="YES" POD_LINT="NO"
|
||||||
- DESTINATION="OS=3.2,name=Apple Watch - 42mm" SCHEME="CoreStore watchOS" SDK=watchsimulator3.2 RUN_TESTS="NO" POD_LINT="NO"
|
- DESTINATION="arch=x86_64" SCHEME="CoreStore OSX" SDK=macosx10.13 RUN_TESTS="YES" POD_LINT="NO"
|
||||||
- DESTINATION="OS=2.2,name=Apple Watch - 42mm" SCHEME="CoreStore watchOS" SDK=watchsimulator3.2 RUN_TESTS="NO" POD_LINT="NO"
|
- DESTINATION="OS=4.0,name=Apple Watch - 42mm" SCHEME="CoreStore watchOS" SDK=watchsimulator4.0 RUN_TESTS="NO" POD_LINT="NO"
|
||||||
- DESTINATION="OS=10.2,name=Apple TV 1080p" SCHEME="CoreStore tvOS" SDK=appletvsimulator10.2 RUN_TESTS="YES" POD_LINT="NO"
|
- DESTINATION="OS=3.2,name=Apple Watch - 42mm" SCHEME="CoreStore watchOS" SDK=watchsimulator4.0 RUN_TESTS="NO" POD_LINT="NO"
|
||||||
- DESTINATION="OS=9.2,name=Apple TV 1080p" SCHEME="CoreStore tvOS" SDK=appletvsimulator10.2 RUN_TESTS="YES" POD_LINT="NO"
|
- DESTINATION="OS=2.2,name=Apple Watch - 42mm" SCHEME="CoreStore watchOS" SDK=watchsimulator4.0 RUN_TESTS="NO" POD_LINT="NO"
|
||||||
|
- DESTINATION="OS=11.0,name=Apple TV 1080p" SCHEME="CoreStore tvOS" SDK=appletvsimulator11.0 RUN_TESTS="YES" POD_LINT="NO"
|
||||||
|
- DESTINATION="OS=10.2,name=Apple TV 1080p" SCHEME="CoreStore tvOS" SDK=appletvsimulator11.0 RUN_TESTS="YES" POD_LINT="NO"
|
||||||
|
- DESTINATION="OS=9.2,name=Apple TV 1080p" SCHEME="CoreStore tvOS" SDK=appletvsimulator11.0 RUN_TESTS="YES" POD_LINT="NO"
|
||||||
before_install:
|
before_install:
|
||||||
- gem install cocoapods --no-rdoc --no-ri --no-document --quiet
|
- gem install cocoapods --no-rdoc --no-ri --no-document --quiet
|
||||||
- gem install xcpretty --no-rdoc --no-ri --no-document --quiet
|
- gem install xcpretty --no-rdoc --no-ri --no-document --quiet
|
||||||
- curl -OlL "https://github.com/Carthage/Carthage/releases/download/0.23.0/Carthage.pkg"
|
- curl -OlL "https://github.com/Carthage/Carthage/releases/download/0.26.0/Carthage.pkg"
|
||||||
- sudo installer -pkg "Carthage.pkg" -target /
|
- sudo installer -pkg "Carthage.pkg" -target /
|
||||||
- rm "Carthage.pkg"
|
- rm "Carthage.pkg"
|
||||||
|
- npm install ios-sim -g
|
||||||
|
- ios-sim start --devicetypeid "com.apple.CoreSimulator.SimDeviceType.iPhone-8, 11.0"
|
||||||
before_script:
|
before_script:
|
||||||
- carthage update --use-submodules
|
- carthage update --use-submodules
|
||||||
script:
|
script:
|
||||||
@@ -38,8 +43,8 @@ script:
|
|||||||
xcodebuild -workspace CoreStore.xcworkspace -scheme "$SCHEME" -sdk "$SDK" -destination "$DESTINATION" -configuration Debug ONLY_ACTIVE_ARCH=NO clean test | xcpretty -c;
|
xcodebuild -workspace CoreStore.xcworkspace -scheme "$SCHEME" -sdk "$SDK" -destination "$DESTINATION" -configuration Debug ONLY_ACTIVE_ARCH=NO clean test | xcpretty -c;
|
||||||
xcodebuild -workspace CoreStore.xcworkspace -scheme "$SCHEME" -sdk "$SDK" -destination "$DESTINATION" -configuration Release ONLY_ACTIVE_ARCH=NO clean test | xcpretty -c;
|
xcodebuild -workspace CoreStore.xcworkspace -scheme "$SCHEME" -sdk "$SDK" -destination "$DESTINATION" -configuration Release ONLY_ACTIVE_ARCH=NO clean test | xcpretty -c;
|
||||||
fi
|
fi
|
||||||
- xcodebuild -workspace "CoreStore.xcworkspace" -scheme "CoreStore iOS" -sdk "iphonesimulator10.3" -destination "OS=10.3,name=iPhone 7" -configuration Debug ONLY_ACTIVE_ARCH=NO clean test | xcpretty -c;
|
- xcodebuild -workspace "CoreStore.xcworkspace" -scheme "CoreStoreDemo" -sdk "iphonesimulator11.0" -destination "OS=11.0,name=iPhone 8" -configuration Debug ONLY_ACTIVE_ARCH=NO build | xcpretty -c;
|
||||||
- xcodebuild -workspace "CoreStore.xcworkspace" -scheme "CoreStore iOS" -sdk "iphonesimulator10.3" -destination "OS=10.3,name=iPhone 7" -configuration Release ONLY_ACTIVE_ARCH=NO clean test | xcpretty -c;
|
- xcodebuild -workspace "CoreStore.xcworkspace" -scheme "CoreStoreDemo" -sdk "iphonesimulator11.0" -destination "OS=11.0,name=iPhone 8" -configuration Release ONLY_ACTIVE_ARCH=NO build | xcpretty -c;
|
||||||
- if [ $POD_LINT == "YES" ]; then
|
- if [ $POD_LINT == "YES" ]; then
|
||||||
pod lib lint --quick;
|
pod lib lint --quick;
|
||||||
fi
|
fi
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
Pod::Spec.new do |s|
|
Pod::Spec.new do |s|
|
||||||
s.name = "CoreStore"
|
s.name = "CoreStore"
|
||||||
s.version = "4.1.4"
|
s.version = "4.2.0"
|
||||||
s.license = "MIT"
|
s.license = "MIT"
|
||||||
s.summary = "Unleashing the real power of Core Data with the elegance and safety of Swift"
|
s.summary = "Unleashing the real power of Core Data with the elegance and safety of Swift"
|
||||||
s.homepage = "https://github.com/JohnEstropia/CoreStore"
|
s.homepage = "https://github.com/JohnEstropia/CoreStore"
|
||||||
|
|||||||
+1
-1
@@ -85,7 +85,7 @@ class ObjectObserverDemoViewController: UIViewController, ObjectObserver {
|
|||||||
|
|
||||||
// MARK: ObjectObserver
|
// MARK: ObjectObserver
|
||||||
|
|
||||||
func objectMonitor(_ monitor: ObjectMonitor<Palette>, didUpdateObject object: Palette, changedPersistentKeys: Set<KeyPath>) {
|
func objectMonitor(_ monitor: ObjectMonitor<Palette>, didUpdateObject object: Palette, changedPersistentKeys: Set<RawKeyPath>) {
|
||||||
|
|
||||||
self.reloadPaletteInfo(object, changedKeys: changedPersistentKeys)
|
self.reloadPaletteInfo(object, changedKeys: changedPersistentKeys)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ class TransactionsDemoViewController: UIViewController, MKMapViewDelegate, Objec
|
|||||||
// none
|
// none
|
||||||
}
|
}
|
||||||
|
|
||||||
func objectMonitor(_ monitor: ObjectMonitor<Place>, didUpdateObject object: Place, changedPersistentKeys: Set<KeyPath>) {
|
func objectMonitor(_ monitor: ObjectMonitor<Place>, didUpdateObject object: Place, changedPersistentKeys: Set<RawKeyPath>) {
|
||||||
|
|
||||||
if let mapView = self.mapView {
|
if let mapView = self.mapView {
|
||||||
|
|
||||||
|
|||||||
@@ -36,33 +36,33 @@ class ImportTests: BaseTestDataTestCase {
|
|||||||
@objc
|
@objc
|
||||||
dynamic func test_ThatAttributeProtocols_BehaveCorrectly() {
|
dynamic func test_ThatAttributeProtocols_BehaveCorrectly() {
|
||||||
|
|
||||||
XCTAssertEqual(NSNumber.cs_fromImportableNativeType(NSNumber(value: true))?.boolValue, true)
|
XCTAssertEqual(NSNumber.cs_fromQueryableNativeType(NSNumber(value: true))?.boolValue, true)
|
||||||
XCTAssertEqual(NSNumber.cs_fromImportableNativeType(NSNumber(value: Int16.max))?.int16Value, Int16.max)
|
XCTAssertEqual(NSNumber.cs_fromQueryableNativeType(NSNumber(value: Int16.max))?.int16Value, Int16.max)
|
||||||
XCTAssertEqual(NSNumber.cs_fromImportableNativeType(NSNumber(value: Int32.max))?.int32Value, Int32.max)
|
XCTAssertEqual(NSNumber.cs_fromQueryableNativeType(NSNumber(value: Int32.max))?.int32Value, Int32.max)
|
||||||
XCTAssertEqual(NSNumber.cs_fromImportableNativeType(NSNumber(value: Int64.max))?.int64Value, Int64.max)
|
XCTAssertEqual(NSNumber.cs_fromQueryableNativeType(NSNumber(value: Int64.max))?.int64Value, Int64.max)
|
||||||
XCTAssertEqual(NSNumber.cs_fromImportableNativeType(NSNumber(value: MAXFLOAT))?.floatValue, MAXFLOAT)
|
XCTAssertEqual(NSNumber.cs_fromQueryableNativeType(NSNumber(value: MAXFLOAT))?.floatValue, MAXFLOAT)
|
||||||
XCTAssertEqual(NSNumber.cs_fromImportableNativeType(NSNumber(value: Double(MAXFLOAT)))?.doubleValue, Double(MAXFLOAT))
|
XCTAssertEqual(NSNumber.cs_fromQueryableNativeType(NSNumber(value: Double(MAXFLOAT)))?.doubleValue, Double(MAXFLOAT))
|
||||||
|
|
||||||
XCTAssertEqual(NSDecimalNumber.cs_fromImportableNativeType(NSDecimalNumber(string: "1"))?.boolValue, true)
|
XCTAssertEqual(NSDecimalNumber.cs_fromQueryableNativeType(NSDecimalNumber(string: "1"))?.boolValue, true)
|
||||||
XCTAssertEqual(NSDecimalNumber.cs_fromImportableNativeType(NSDecimalNumber(string: Int16.max.description))?.int16Value, Int16.max)
|
XCTAssertEqual(NSDecimalNumber.cs_fromQueryableNativeType(NSDecimalNumber(string: Int16.max.description))?.int16Value, Int16.max)
|
||||||
XCTAssertEqual(NSDecimalNumber.cs_fromImportableNativeType(NSDecimalNumber(string: Int32.max.description))?.int32Value, Int32.max)
|
XCTAssertEqual(NSDecimalNumber.cs_fromQueryableNativeType(NSDecimalNumber(string: Int32.max.description))?.int32Value, Int32.max)
|
||||||
XCTAssertEqual(NSDecimalNumber.cs_fromImportableNativeType(NSDecimalNumber(string: Int64.max.description))?.int64Value, Int64.max)
|
XCTAssertEqual(NSDecimalNumber.cs_fromQueryableNativeType(NSDecimalNumber(string: Int64.max.description))?.int64Value, Int64.max)
|
||||||
XCTAssertEqual(NSDecimalNumber.cs_fromImportableNativeType(NSDecimalNumber(string: MAXFLOAT.description))?.doubleValue, NSDecimalNumber(string: MAXFLOAT.description).doubleValue)
|
XCTAssertEqual(NSDecimalNumber.cs_fromQueryableNativeType(NSDecimalNumber(string: MAXFLOAT.description))?.doubleValue, NSDecimalNumber(string: MAXFLOAT.description).doubleValue)
|
||||||
XCTAssertEqual(NSDecimalNumber.cs_fromImportableNativeType(NSDecimalNumber(string: MAXFLOAT.description))?.floatValue, NSDecimalNumber(string: MAXFLOAT.description).floatValue)
|
XCTAssertEqual(NSDecimalNumber.cs_fromQueryableNativeType(NSDecimalNumber(string: MAXFLOAT.description))?.floatValue, NSDecimalNumber(string: MAXFLOAT.description).floatValue)
|
||||||
|
|
||||||
XCTAssertEqual(NSNumber.cs_fromImportableNativeType(NSDecimalNumber(string: "1"))?.boolValue, true)
|
XCTAssertEqual(NSNumber.cs_fromQueryableNativeType(NSDecimalNumber(string: "1"))?.boolValue, true)
|
||||||
XCTAssertEqual(NSNumber.cs_fromImportableNativeType(NSDecimalNumber(string: Int16.max.description))?.int16Value, Int16.max)
|
XCTAssertEqual(NSNumber.cs_fromQueryableNativeType(NSDecimalNumber(string: Int16.max.description))?.int16Value, Int16.max)
|
||||||
XCTAssertEqual(NSNumber.cs_fromImportableNativeType(NSDecimalNumber(string: Int32.max.description))?.int32Value, Int32.max)
|
XCTAssertEqual(NSNumber.cs_fromQueryableNativeType(NSDecimalNumber(string: Int32.max.description))?.int32Value, Int32.max)
|
||||||
XCTAssertEqual(NSNumber.cs_fromImportableNativeType(NSDecimalNumber(string: Int64.max.description))?.int64Value, Int64.max)
|
XCTAssertEqual(NSNumber.cs_fromQueryableNativeType(NSDecimalNumber(string: Int64.max.description))?.int64Value, Int64.max)
|
||||||
XCTAssertEqual(NSNumber.cs_fromImportableNativeType(NSDecimalNumber(string: MAXFLOAT.description))?.doubleValue, NSDecimalNumber(string: MAXFLOAT.description).doubleValue)
|
XCTAssertEqual(NSNumber.cs_fromQueryableNativeType(NSDecimalNumber(string: MAXFLOAT.description))?.doubleValue, NSDecimalNumber(string: MAXFLOAT.description).doubleValue)
|
||||||
XCTAssertEqual(NSNumber.cs_fromImportableNativeType(NSDecimalNumber(string: MAXFLOAT.description))?.floatValue, NSDecimalNumber(string: MAXFLOAT.description).floatValue)
|
XCTAssertEqual(NSNumber.cs_fromQueryableNativeType(NSDecimalNumber(string: MAXFLOAT.description))?.floatValue, NSDecimalNumber(string: MAXFLOAT.description).floatValue)
|
||||||
|
|
||||||
XCTAssertNil(NSDecimalNumber.cs_fromImportableNativeType(NSNumber(value: true)))
|
XCTAssertNil(NSDecimalNumber.cs_fromQueryableNativeType(NSNumber(value: true)))
|
||||||
XCTAssertNil(NSDecimalNumber.cs_fromImportableNativeType(NSNumber(value: Int16.max)))
|
XCTAssertNil(NSDecimalNumber.cs_fromQueryableNativeType(NSNumber(value: Int16.max)))
|
||||||
XCTAssertNil(NSDecimalNumber.cs_fromImportableNativeType(NSNumber(value: Int32.max)))
|
XCTAssertNil(NSDecimalNumber.cs_fromQueryableNativeType(NSNumber(value: Int32.max)))
|
||||||
XCTAssertNil(NSDecimalNumber.cs_fromImportableNativeType(NSNumber(value: Int64.max)))
|
XCTAssertNil(NSDecimalNumber.cs_fromQueryableNativeType(NSNumber(value: Int64.max)))
|
||||||
XCTAssertNil(NSDecimalNumber.cs_fromImportableNativeType(NSNumber(value: MAXFLOAT)))
|
XCTAssertNil(NSDecimalNumber.cs_fromQueryableNativeType(NSNumber(value: MAXFLOAT)))
|
||||||
XCTAssertNil(NSDecimalNumber.cs_fromImportableNativeType(NSNumber(value: Double(MAXFLOAT))))
|
XCTAssertNil(NSDecimalNumber.cs_fromQueryableNativeType(NSNumber(value: Double(MAXFLOAT))))
|
||||||
|
|
||||||
XCTAssertEqual(true.cs_toQueryableNativeType(), NSNumber(value: true))
|
XCTAssertEqual(true.cs_toQueryableNativeType(), NSNumber(value: true))
|
||||||
XCTAssertEqual(Int16.max.cs_toQueryableNativeType(), NSNumber(value: Int16.max))
|
XCTAssertEqual(Int16.max.cs_toQueryableNativeType(), NSNumber(value: Int16.max))
|
||||||
|
|||||||
@@ -198,60 +198,58 @@ class ListObserverTests: BaseTestDataTestCase {
|
|||||||
return events == 0
|
return events == 0
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
for _ in 1 ... 2 {
|
|
||||||
|
|
||||||
let didUpdateObjectExpectation = self.expectation(
|
let didUpdateObjectExpectation = self.expectation(
|
||||||
forNotification: "listMonitor:didUpdateObject:atIndexPath:",
|
forNotification: "listMonitor:didUpdateObject:atIndexPath:",
|
||||||
object: observer,
|
object: observer,
|
||||||
handler: { (note) -> Bool in
|
handler: { (note) -> Bool in
|
||||||
|
|
||||||
XCTAssert(events == 1 || events == 2)
|
XCTAssert(events == 1 || events == 2)
|
||||||
|
|
||||||
let userInfo = note.userInfo
|
let userInfo = note.userInfo
|
||||||
XCTAssertNotNil(userInfo)
|
XCTAssertNotNil(userInfo)
|
||||||
XCTAssertEqual(
|
XCTAssertEqual(
|
||||||
Set(userInfo?.keys.map({ $0 as! String }) ?? []),
|
Set(userInfo?.keys.map({ $0 as! String }) ?? []),
|
||||||
["indexPath", "object"]
|
["indexPath", "object"]
|
||||||
)
|
)
|
||||||
|
|
||||||
let indexPath = userInfo?["indexPath"] as? NSIndexPath
|
let indexPath = userInfo?["indexPath"] as? NSIndexPath
|
||||||
let object = userInfo?["object"] as? TestEntity1
|
let object = userInfo?["object"] as? TestEntity1
|
||||||
|
|
||||||
switch object?.testEntityID {
|
switch object?.testEntityID {
|
||||||
|
|
||||||
case NSNumber(value: 101)?:
|
case NSNumber(value: 101)?:
|
||||||
XCTAssertEqual(indexPath?.index(atPosition: 0), 1)
|
XCTAssertEqual(indexPath?.index(atPosition: 0), 1)
|
||||||
XCTAssertEqual(indexPath?.index(atPosition: 1), 0)
|
XCTAssertEqual(indexPath?.index(atPosition: 1), 0)
|
||||||
|
|
||||||
XCTAssertEqual(object?.testBoolean, NSNumber(value: true))
|
XCTAssertEqual(object?.testBoolean, NSNumber(value: true))
|
||||||
XCTAssertEqual(object?.testNumber, NSNumber(value: 11))
|
XCTAssertEqual(object?.testNumber, NSNumber(value: 11))
|
||||||
XCTAssertEqual(object?.testDecimal, NSDecimalNumber(string: "11"))
|
XCTAssertEqual(object?.testDecimal, NSDecimalNumber(string: "11"))
|
||||||
XCTAssertEqual(object?.testString, "nil:TestEntity1:11")
|
XCTAssertEqual(object?.testString, "nil:TestEntity1:11")
|
||||||
XCTAssertEqual(object?.testData, ("nil:TestEntity1:11" as NSString).data(using: String.Encoding.utf8.rawValue)!)
|
XCTAssertEqual(object?.testData, ("nil:TestEntity1:11" as NSString).data(using: String.Encoding.utf8.rawValue)!)
|
||||||
XCTAssertEqual(object?.testDate, self.dateFormatter.date(from: "2000-01-11T00:00:00Z")!)
|
XCTAssertEqual(object?.testDate, self.dateFormatter.date(from: "2000-01-11T00:00:00Z")!)
|
||||||
|
|
||||||
case NSNumber(value: 102)?:
|
case NSNumber(value: 102)?:
|
||||||
XCTAssertEqual(indexPath?.index(atPosition: 0), 0)
|
XCTAssertEqual(indexPath?.index(atPosition: 0), 0)
|
||||||
XCTAssertEqual(indexPath?.index(atPosition: 1), 0)
|
XCTAssertEqual(indexPath?.index(atPosition: 1), 0)
|
||||||
|
|
||||||
XCTAssertEqual(object?.testBoolean, NSNumber(value: false))
|
XCTAssertEqual(object?.testBoolean, NSNumber(value: false))
|
||||||
XCTAssertEqual(object?.testNumber, NSNumber(value: 22))
|
XCTAssertEqual(object?.testNumber, NSNumber(value: 22))
|
||||||
XCTAssertEqual(object?.testDecimal, NSDecimalNumber(string: "22"))
|
XCTAssertEqual(object?.testDecimal, NSDecimalNumber(string: "22"))
|
||||||
XCTAssertEqual(object?.testString, "nil:TestEntity1:22")
|
XCTAssertEqual(object?.testString, "nil:TestEntity1:22")
|
||||||
XCTAssertEqual(object?.testData, ("nil:TestEntity1:22" as NSString).data(using: String.Encoding.utf8.rawValue)!)
|
XCTAssertEqual(object?.testData, ("nil:TestEntity1:22" as NSString).data(using: String.Encoding.utf8.rawValue)!)
|
||||||
XCTAssertEqual(object?.testDate, self.dateFormatter.date(from: "2000-01-22T00:00:00Z")!)
|
XCTAssertEqual(object?.testDate, self.dateFormatter.date(from: "2000-01-22T00:00:00Z")!)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
XCTFail()
|
XCTFail()
|
||||||
}
|
|
||||||
defer {
|
|
||||||
|
|
||||||
events += 1
|
|
||||||
}
|
|
||||||
return events == 1 || events == 2
|
|
||||||
}
|
}
|
||||||
)
|
defer {
|
||||||
}
|
|
||||||
|
events += 1
|
||||||
|
}
|
||||||
|
return events == 1 || events == 2
|
||||||
|
}
|
||||||
|
)
|
||||||
let didChangeExpectation = self.expectation(
|
let didChangeExpectation = self.expectation(
|
||||||
forNotification: "listMonitorDidChange:",
|
forNotification: "listMonitorDidChange:",
|
||||||
object: observer,
|
object: observer,
|
||||||
@@ -453,38 +451,35 @@ class ListObserverTests: BaseTestDataTestCase {
|
|||||||
return events == 0
|
return events == 0
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
for _ in 1 ... 2 {
|
let didUpdateObjectExpectation = self.expectation(
|
||||||
|
forNotification: "listMonitor:didDeleteObject:fromIndexPath:",
|
||||||
|
object: observer,
|
||||||
|
handler: { (note) -> Bool in
|
||||||
|
|
||||||
let didUpdateObjectExpectation = self.expectation(
|
XCTAssert(events == 1 || events == 2)
|
||||||
forNotification: "listMonitor:didDeleteObject:fromIndexPath:",
|
|
||||||
object: observer,
|
|
||||||
handler: { (note) -> Bool in
|
|
||||||
|
|
||||||
XCTAssert(events == 1 || events == 2)
|
let userInfo = note.userInfo
|
||||||
|
XCTAssertNotNil(userInfo)
|
||||||
|
XCTAssertEqual(
|
||||||
|
Set(userInfo?.keys.map({ $0 as! String }) ?? []),
|
||||||
|
["indexPath", "object"]
|
||||||
|
)
|
||||||
|
|
||||||
let userInfo = note.userInfo
|
let indexPath = userInfo?["indexPath"] as? NSIndexPath
|
||||||
XCTAssertNotNil(userInfo)
|
|
||||||
XCTAssertEqual(
|
|
||||||
Set(userInfo?.keys.map({ $0 as! String }) ?? []),
|
|
||||||
["indexPath", "object"]
|
|
||||||
)
|
|
||||||
|
|
||||||
let indexPath = userInfo?["indexPath"] as? NSIndexPath
|
XCTAssertEqual(indexPath?.section, 0)
|
||||||
|
XCTAssert(indexPath?.index(atPosition: 1) == 0 || indexPath?.index(atPosition: 1) == 1)
|
||||||
|
|
||||||
XCTAssertEqual(indexPath?.section, 0)
|
let object = userInfo?["object"] as? TestEntity1
|
||||||
XCTAssert(indexPath?.index(atPosition: 1) == 0 || indexPath?.index(atPosition: 1) == 1)
|
XCTAssertEqual(object?.isDeleted, true)
|
||||||
|
|
||||||
let object = userInfo?["object"] as? TestEntity1
|
defer {
|
||||||
XCTAssertEqual(object?.isDeleted, true)
|
|
||||||
|
|
||||||
defer {
|
events += 1
|
||||||
|
|
||||||
events += 1
|
|
||||||
}
|
|
||||||
return events == 1 || events == 2
|
|
||||||
}
|
}
|
||||||
)
|
return events == 1 || events == 2
|
||||||
}
|
}
|
||||||
|
)
|
||||||
let didDeleteSectionExpectation = self.expectation(
|
let didDeleteSectionExpectation = self.expectation(
|
||||||
forNotification: "listMonitor:didDeleteSection:fromSectionIndex:",
|
forNotification: "listMonitor:didDeleteSection:fromSectionIndex:",
|
||||||
object: observer,
|
object: observer,
|
||||||
@@ -531,10 +526,11 @@ class ListObserverTests: BaseTestDataTestCase {
|
|||||||
stack.perform(
|
stack.perform(
|
||||||
asynchronous: { (transaction) -> Bool in
|
asynchronous: { (transaction) -> Bool in
|
||||||
|
|
||||||
transaction.deleteAll(
|
let count = transaction.deleteAll(
|
||||||
From<TestEntity1>(),
|
From<TestEntity1>(),
|
||||||
Where(#keyPath(TestEntity1.testBoolean), isEqualTo: false)
|
Where(#keyPath(TestEntity1.testBoolean), isEqualTo: false)
|
||||||
)
|
)
|
||||||
|
XCTAssertEqual(count, 2)
|
||||||
return transaction.hasChanges
|
return transaction.hasChanges
|
||||||
},
|
},
|
||||||
success: { (hasChanges) in
|
success: { (hasChanges) in
|
||||||
|
|||||||
@@ -219,7 +219,7 @@ class TestObjectObserver: ObjectObserver {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func objectMonitor(_ monitor: ObjectMonitor<TestEntity1>, didUpdateObject object: TestEntity1, changedPersistentKeys: Set<KeyPath>) {
|
func objectMonitor(_ monitor: ObjectMonitor<TestEntity1>, didUpdateObject object: TestEntity1, changedPersistentKeys: Set<String>) {
|
||||||
|
|
||||||
NotificationCenter.default.post(
|
NotificationCenter.default.post(
|
||||||
name: NSNotification.Name(rawValue: "objectMonitor:didUpdateObject:changedPersistentKeys:"),
|
name: NSNotification.Name(rawValue: "objectMonitor:didUpdateObject:changedPersistentKeys:"),
|
||||||
|
|||||||
@@ -18,10 +18,10 @@ Unleashing the real power of Core Data with the elegance and safety of Swift
|
|||||||
<br />
|
<br />
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
* **Swift 3.1:** iOS 8+ / macOS 10.10+ / watchOS 2.0+ / tvOS 9.0+
|
* **Swift 3.2:** iOS 8+ / macOS 10.10+ / watchOS 2.0+ / tvOS 9.0+
|
||||||
* Beta support: [Swift 3.2](https://github.com/JohnEstropia/CoreStore/tree/prototype/Swift_3_2), [Swift 4.0](https://github.com/JohnEstropia/CoreStore/tree/prototype/Swift_4_0)
|
* Other Swift versions: [Swift 3.1(version 4.1.4)](https://github.com/JohnEstropia/CoreStore/tree/4.1.4), [Swift 4.0](https://github.com/JohnEstropia/CoreStore/tree/5.0.0)
|
||||||
|
|
||||||
Upgrading from CoreStore 3.x to 4.x? Check out the [new features](#features) and make sure to read the [Migration guide](#upgrading-from-3xx-to-4xx).
|
Upgrading from CoreStore 4.1 (Swift 3.1) to 4.2 (Swift 3.2)? Check out the [new features](#features) and make sure to read the [Change logs](https://github.com/JohnEstropia/CoreStore/releases).
|
||||||
|
|
||||||
CoreStore is now part of the [Swift Source Compatibility projects](https://swift.org/source-compatibility/#current-list-of-projects).
|
CoreStore is now part of the [Swift Source Compatibility projects](https://swift.org/source-compatibility/#current-list-of-projects).
|
||||||
|
|
||||||
@@ -38,9 +38,9 @@ CoreStore was (and is) heavily shaped by real-world needs of developing data-dep
|
|||||||
- **Clean fetching and querying API.** Fetching objects is easy, but querying for raw aggregates (`min`, `max`, etc.) and raw property values is now just as convenient. *(See [Fetching and querying](#fetching-and-querying))*
|
- **Clean fetching and querying API.** Fetching objects is easy, but querying for raw aggregates (`min`, `max`, etc.) and raw property values is now just as convenient. *(See [Fetching and querying](#fetching-and-querying))*
|
||||||
- **Type-safe, easy to configure observers.** You don't have to deal with the burden of setting up `NSFetchedResultsController`s and KVO. As an added bonus, `ListMonitor`s and `ObjectMonitor`s can have multiple observers. This means you can have multiple view controllers efficiently share a single resource! *(See [Observing changes and notifications](#observing-changes-and-notifications))*
|
- **Type-safe, easy to configure observers.** You don't have to deal with the burden of setting up `NSFetchedResultsController`s and KVO. As an added bonus, `ListMonitor`s and `ObjectMonitor`s can have multiple observers. This means you can have multiple view controllers efficiently share a single resource! *(See [Observing changes and notifications](#observing-changes-and-notifications))*
|
||||||
- **Efficient importing utilities.** Map your entities once with their corresponding import source (JSON for example), and importing from *transactions* becomes elegant. Uniquing is also done with an efficient find-and-replace algorithm. *(See [Importing data](#importing-data))*
|
- **Efficient importing utilities.** Map your entities once with their corresponding import source (JSON for example), and importing from *transactions* becomes elegant. Uniquing is also done with an efficient find-and-replace algorithm. *(See [Importing data](#importing-data))*
|
||||||
- ⭐️ **New in 4.0: Say goodbye to *.xcdatamodeld* files!** The new `CoreStoreObject` is *the* replacement to `NSManagedObject`. `CoreStoreObject` subclasses can declare type-safe properties all in Swift code, no need to maintain separate resource files for the models. As bonus, these special properties support custom types, and can be used to create type-safe keypaths and queries. *(See [Type-safe `CoreStoreObject`s](#type-safe-corestoreobjects))*
|
- **Say goodbye to *.xcdatamodeld* files!** The new `CoreStoreObject` is *the* replacement to `NSManagedObject`. `CoreStoreObject` subclasses can declare type-safe properties all in Swift code, no need to maintain separate resource files for the models. As bonus, these special properties support custom types, and can be used to create type-safe keypaths and queries. *(See [Type-safe `CoreStoreObject`s](#type-safe-corestoreobjects))*
|
||||||
- **Progressive migrations.** No need to think how to migrate from all previous model versions to your latest model. Just tell the `DataStack` the sequence of version strings (`MigrationChain`s) and CoreStore will automatically use progressive migrations when needed. *(See [Migrations](#migrations))*
|
- **Progressive migrations.** No need to think how to migrate from all previous model versions to your latest model. Just tell the `DataStack` the sequence of version strings (`MigrationChain`s) and CoreStore will automatically use progressive migrations when needed. *(See [Migrations](#migrations))*
|
||||||
- ⭐️ **New in 4.0: Easier custom migrations.** Say goodbye to *.xcmappingmodel* files; CoreStore can now infer entity mappings when possible, while still allowing an easy way to write custom mappings. *(See [Migrations](#migrations))*
|
- **Easier custom migrations.** Say goodbye to *.xcmappingmodel* files; CoreStore can now infer entity mappings when possible, while still allowing an easy way to write custom mappings. *(See [Migrations](#migrations))*
|
||||||
- **Plug-in your own logging framework.** Although a default logger is built-in, all logging, asserting, and error reporting can be funneled to `CoreStoreLogger` protocol implementations. *(See [Logging and error reporting](#logging-and-error-reporting))*
|
- **Plug-in your own logging framework.** Although a default logger is built-in, all logging, asserting, and error reporting can be funneled to `CoreStoreLogger` protocol implementations. *(See [Logging and error reporting](#logging-and-error-reporting))*
|
||||||
- **Heavy support for multiple persistent stores per data stack.** CoreStore lets you manage separate stores in a single `DataStack`, just the way *.xcdatamodeld* configurations are designed to. CoreStore will also manage one stack by default, but you can create and manage as many as you need. *(See [Setting up](#setting-up))*
|
- **Heavy support for multiple persistent stores per data stack.** CoreStore lets you manage separate stores in a single `DataStack`, just the way *.xcdatamodeld* configurations are designed to. CoreStore will also manage one stack by default, but you can create and manage as many as you need. *(See [Setting up](#setting-up))*
|
||||||
- **Free to name entities and their class names independently.** CoreStore gets around a restriction with other Core Data wrappers where the entity name should be the same as the `NSManagedObject` subclass name. CoreStore loads entity-to-class mappings from the managed object model file, so you can assign different names for the entities and their class names.
|
- **Free to name entities and their class names independently.** CoreStore gets around a restriction with other Core Data wrappers where the entity name should be the same as the `NSManagedObject` subclass name. CoreStore loads entity-to-class mappings from the managed object model file, so you can assign different names for the entities and their class names.
|
||||||
@@ -95,8 +95,6 @@ CoreStore was (and is) heavily shaped by real-world needs of developing data-dep
|
|||||||
- [Roadmap](#roadmap)
|
- [Roadmap](#roadmap)
|
||||||
- [Installation](#installation)
|
- [Installation](#installation)
|
||||||
- [Changesets](#changesets)
|
- [Changesets](#changesets)
|
||||||
- [Upgrading from 3.x.x to 4.x.x](#upgrading-from-3xx-to-4xx)
|
|
||||||
- [Other Releases](#other-releases)
|
|
||||||
- [Contact](#contact)
|
- [Contact](#contact)
|
||||||
- [Who uses CoreStore?](#who-uses-corestore)
|
- [Who uses CoreStore?](#who-uses-corestore)
|
||||||
- [License](#license)
|
- [License](#license)
|
||||||
@@ -1447,7 +1445,7 @@ class MyViewController: UIViewController, ObjectObserver {
|
|||||||
// ...
|
// ...
|
||||||
}
|
}
|
||||||
|
|
||||||
func objectMonitor(monitor: ObjectMonitor<MyPersonEntity>, didUpdateObject object: MyPersonEntity, changedPersistentKeys: Set<KeyPath>) {
|
func objectMonitor(monitor: ObjectMonitor<MyPersonEntity>, didUpdateObject object: MyPersonEntity, changedPersistentKeys: Set<RawKeyPath>) {
|
||||||
// ...
|
// ...
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1675,7 +1673,7 @@ To use these syntax sugars, include *CoreStoreBridge.h* in your Objective-C sour
|
|||||||
Starting CoreStore 4.0, we can now create persisted objects without depending on *.xcdatamodeld* Core Data files. The new `CoreStoreObject` subclass replaces `NSManagedObject`, and specially-typed properties declared on these classes will be synthesized as Core Data attributes.
|
Starting CoreStore 4.0, we can now create persisted objects without depending on *.xcdatamodeld* Core Data files. The new `CoreStoreObject` subclass replaces `NSManagedObject`, and specially-typed properties declared on these classes will be synthesized as Core Data attributes.
|
||||||
```swift
|
```swift
|
||||||
class Animal: CoreStoreObject {
|
class Animal: CoreStoreObject {
|
||||||
let species = Value.Required<String>("species")
|
let species = Value.Required<String>("species", initial: "")
|
||||||
}
|
}
|
||||||
|
|
||||||
class Dog: Animal {
|
class Dog: Animal {
|
||||||
@@ -1684,14 +1682,14 @@ class Dog: Animal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class Person: CoreStoreObject {
|
class Person: CoreStoreObject {
|
||||||
let name = Value.Required<String>("name")
|
let name = Value.Required<String>("name", initial: "")
|
||||||
let pets = Relationship.ToManyUnordered<Dog>("pets", inverse: { $0.master })
|
let pets = Relationship.ToManyUnordered<Dog>("pets", inverse: { $0.master })
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
The property names to be saved to Core Data is specified as the `keyPath` argument. This lets us refactor our Swift code without affecting the underlying database. For example:
|
The property names to be saved to Core Data is specified as the `keyPath` argument. This lets us refactor our Swift code without affecting the underlying database. For example:
|
||||||
```swift
|
```swift
|
||||||
class Person: CoreStoreObject {
|
class Person: CoreStoreObject {
|
||||||
private let _name = Value.Required<String>("name")
|
private let _name = Value.Required<String>("name", initial: "")
|
||||||
// ...
|
// ...
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -1832,22 +1830,6 @@ Add all *.swift* files to your project.
|
|||||||
To use the Objective-C syntax sugars, import *CoreStoreBridge.h* in your *.m* source files.
|
To use the Objective-C syntax sugars, import *CoreStoreBridge.h* in your *.m* source files.
|
||||||
|
|
||||||
# Changesets
|
# Changesets
|
||||||
### Upgrading from 3.x.x to 4.x.x
|
|
||||||
**Obsoleted**
|
|
||||||
- `LegacySQLiteStore` is now finally obsoleted in favor of `SQLiteStore`. For sqlite files that were created previously with `LegacySQLiteStore`, make sure to use the `SQLiteStore.legacy(...)` factory method to create an `SQLiteStore` that can load the file from the legacy file path.
|
|
||||||
- `SQLiteStore.init(...)`'s `mappingModelBundles` argument is now obsolete. The new initializer accepts a `migrationMappingProviders` optional argument where explicit mapping sources are declared. For reference on how to do this, read on [Custom migrations](#custom-migrations).
|
|
||||||
|
|
||||||
**Deprecated**
|
|
||||||
- `DataStack.beginAsynchronous(...)`, `DataStack.beginSynchronous(...)`, `AsynchronousDataTransaction.commit(...)`, and `SynchronousDataTransaction.commit(...)` are now deprecated in favor of `DataStack.perform(asynchronous:...)` and `DataStack.perform(synchronous:...)` family of methods. These new `perform(...)` methods are auto-commit, meaning the transaction automatically calls `commit()` internally after the transction closure completes. To roll-back and cancel a transaction, call `try transaction.cancel()`. Read [Saving and processing transactions](#saving-and-processing-transactions) for more details.
|
|
||||||
|
|
||||||
**Other Changes**
|
|
||||||
- `ListMonitor.refetch(...)` now works by recreating its internal `NSFetchedResultsController`. Previously `refetch(...)` would only apply new `FetchClause`s on top of previous fetches. Now all `FetchClauses` are required to be passed to `refetch(...)` each time it is called.
|
|
||||||
- New important concepts on "Dynamic Models", "Schema", and "Schema Histories".
|
|
||||||
- **Dynamic Models** (`DynamicObject` protocol): These are Core Data object types that any `NSManagedObject` or `CoreStoreObject`s conform to. *(See [Type-safe `CoreStoreObject`s](#type-safe-corestoreobjects))*
|
|
||||||
- **Version Schema** (`DynamicSchema` protocol): These types contain info for a single model version, as well as entities that belong to it. Currently supports `XcodeDataModelSchema` (*.xcdatamodeld* file), `CoreStoreSchema`, or `UnsafeDataModelSchema`. *(See [Migrations](#migrations))*
|
|
||||||
- **Schema History** (`SchemaHistory` class): This is now the preferred way to express all models to the `DataStack`. This class contains info to all the `DynamicSchema` across multiple model versions. *(See [Migrations](#migrations))*
|
|
||||||
|
|
||||||
### Other Releases
|
|
||||||
|
|
||||||
For the full Changelog, refer to the [Releases](https://github.com/JohnEstropia/CoreStore/releases) page.
|
For the full Changelog, refer to the [Releases](https://github.com/JohnEstropia/CoreStore/releases) page.
|
||||||
|
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
|
|||||||
- parameter into: the `Into` clause indicating the destination `NSManagedObject` or `CoreStoreObject` entity type and the destination configuration
|
- parameter into: the `Into` clause indicating the destination `NSManagedObject` or `CoreStoreObject` entity type and the destination configuration
|
||||||
- returns: a new `NSManagedObject` or `CoreStoreObject` instance of the specified entity type.
|
- returns: a new `NSManagedObject` or `CoreStoreObject` instance of the specified entity type.
|
||||||
*/
|
*/
|
||||||
public override func create<T: DynamicObject>(_ into: Into<T>) -> T {
|
public override func create<T>(_ into: Into<T>) -> T {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
!self.isCommitted,
|
!self.isCommitted,
|
||||||
@@ -133,7 +133,7 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
|
|||||||
- parameter objectID: the `NSManagedObjectID` for the object to be edited
|
- parameter objectID: the `NSManagedObjectID` for the object to be edited
|
||||||
- returns: an editable proxy for the specified `NSManagedObject` or `CoreStoreObject`.
|
- returns: an editable proxy for the specified `NSManagedObject` or `CoreStoreObject`.
|
||||||
*/
|
*/
|
||||||
public override func edit<T: DynamicObject>(_ into: Into<T>, _ objectID: NSManagedObjectID) -> T? {
|
public override func edit<T>(_ into: Into<T>, _ objectID: NSManagedObjectID) -> T? {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
!self.isCommitted,
|
!self.isCommitted,
|
||||||
@@ -267,9 +267,9 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
|
|||||||
}
|
}
|
||||||
switch childTransaction.result {
|
switch childTransaction.result {
|
||||||
|
|
||||||
case nil: return nil
|
case .none: return nil
|
||||||
case (let hasChanges, nil)?: return SaveResult(hasChanges: hasChanges)
|
case .some(let hasChanges, nil): return SaveResult(hasChanges: hasChanges)
|
||||||
case (_, let error?)?: return SaveResult(error)
|
case .some(_, let error?): return SaveResult(error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ internal protocol AttributeProtocol: class {
|
|||||||
|
|
||||||
static var attributeType: NSAttributeType { get }
|
static var attributeType: NSAttributeType { get }
|
||||||
|
|
||||||
var keyPath: KeyPath { get }
|
var keyPath: RawKeyPath { get }
|
||||||
var isOptional: Bool { get }
|
var isOptional: Bool { get }
|
||||||
var isIndexed: Bool { get }
|
var isIndexed: Bool { get }
|
||||||
var isTransient: Bool { get }
|
var isTransient: Bool { get }
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
|
|||||||
- returns: the number of `DynamicObject`s deleted
|
- returns: the number of `DynamicObject`s deleted
|
||||||
*/
|
*/
|
||||||
@discardableResult
|
@discardableResult
|
||||||
public func deleteAll<T: DynamicObject>(_ from: From<T>, _ deleteClauses: DeleteClause...) -> Int? {
|
public func deleteAll<T>(_ from: From<T>, _ deleteClauses: DeleteClause...) -> Int? {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
@@ -57,7 +57,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
|
|||||||
- returns: the number of `DynamicObject`s deleted
|
- returns: the number of `DynamicObject`s deleted
|
||||||
*/
|
*/
|
||||||
@discardableResult
|
@discardableResult
|
||||||
public func deleteAll<T: DynamicObject>(_ from: From<T>, _ deleteClauses: [DeleteClause]) -> Int? {
|
public func deleteAll<T>(_ from: From<T>, _ deleteClauses: [DeleteClause]) -> Int? {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
@@ -121,7 +121,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: the first `DynamicObject` instance that satisfies the specified `FetchClause`s
|
- returns: the first `DynamicObject` instance that satisfies the specified `FetchClause`s
|
||||||
*/
|
*/
|
||||||
public func fetchOne<T: DynamicObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> T? {
|
public func fetchOne<T>(_ from: From<T>, _ fetchClauses: FetchClause...) -> T? {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
@@ -137,7 +137,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: the first `DynamicObject` instance that satisfies the specified `FetchClause`s
|
- returns: the first `DynamicObject` instance that satisfies the specified `FetchClause`s
|
||||||
*/
|
*/
|
||||||
public func fetchOne<T: DynamicObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> T? {
|
public func fetchOne<T>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> T? {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
@@ -153,7 +153,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: all `DynamicObject` instances that satisfy the specified `FetchClause`s
|
- returns: all `DynamicObject` instances that satisfy the specified `FetchClause`s
|
||||||
*/
|
*/
|
||||||
public func fetchAll<T: DynamicObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> [T]? {
|
public func fetchAll<T>(_ from: From<T>, _ fetchClauses: FetchClause...) -> [T]? {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
@@ -169,7 +169,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: all `DynamicObject` instances that satisfy the specified `FetchClause`s
|
- returns: all `DynamicObject` instances that satisfy the specified `FetchClause`s
|
||||||
*/
|
*/
|
||||||
public func fetchAll<T: DynamicObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> [T]? {
|
public func fetchAll<T>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> [T]? {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
@@ -185,7 +185,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: the number `DynamicObject`s that satisfy the specified `FetchClause`s
|
- returns: the number `DynamicObject`s that satisfy the specified `FetchClause`s
|
||||||
*/
|
*/
|
||||||
public func fetchCount<T: DynamicObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> Int? {
|
public func fetchCount<T>(_ from: From<T>, _ fetchClauses: FetchClause...) -> Int? {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
@@ -201,7 +201,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: the number `DynamicObject`s that satisfy the specified `FetchClause`s
|
- returns: the number `DynamicObject`s that satisfy the specified `FetchClause`s
|
||||||
*/
|
*/
|
||||||
public func fetchCount<T: DynamicObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> Int? {
|
public func fetchCount<T>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> Int? {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
@@ -217,7 +217,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s
|
- returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s
|
||||||
*/
|
*/
|
||||||
public func fetchObjectID<T: DynamicObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> NSManagedObjectID? {
|
public func fetchObjectID<T>(_ from: From<T>, _ fetchClauses: FetchClause...) -> NSManagedObjectID? {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
@@ -233,7 +233,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s
|
- returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s
|
||||||
*/
|
*/
|
||||||
public func fetchObjectID<T: DynamicObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> NSManagedObjectID? {
|
public func fetchObjectID<T>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> NSManagedObjectID? {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
@@ -249,7 +249,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s
|
- returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s
|
||||||
*/
|
*/
|
||||||
public func fetchObjectIDs<T: DynamicObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> [NSManagedObjectID]? {
|
public func fetchObjectIDs<T>(_ from: From<T>, _ fetchClauses: FetchClause...) -> [NSManagedObjectID]? {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
@@ -265,7 +265,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s
|
- returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s
|
||||||
*/
|
*/
|
||||||
public func fetchObjectIDs<T: DynamicObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> [NSManagedObjectID]? {
|
public func fetchObjectIDs<T>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> [NSManagedObjectID]? {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
@@ -287,7 +287,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
|
|||||||
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
||||||
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
||||||
*/
|
*/
|
||||||
public func queryValue<T: DynamicObject, U: QueryableAttributeType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: QueryClause...) -> U? {
|
public func queryValue<T, U: QueryableAttributeType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: QueryClause...) -> U? {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
@@ -306,7 +306,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
|
|||||||
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
||||||
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
||||||
*/
|
*/
|
||||||
public func queryValue<T: DynamicObject, U: QueryableAttributeType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: [QueryClause]) -> U? {
|
public func queryValue<T, U: QueryableAttributeType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: [QueryClause]) -> U? {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
@@ -325,7 +325,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
|
|||||||
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
||||||
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
||||||
*/
|
*/
|
||||||
public func queryAttributes<T: DynamicObject>(_ from: From<T>, _ selectClause: Select<NSDictionary>, _ queryClauses: QueryClause...) -> [[String: Any]]? {
|
public func queryAttributes<T>(_ from: From<T>, _ selectClause: Select<NSDictionary>, _ queryClauses: QueryClause...) -> [[String: Any]]? {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
@@ -344,7 +344,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
|
|||||||
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
||||||
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
||||||
*/
|
*/
|
||||||
public func queryAttributes<T: DynamicObject>(_ from: From<T>, _ selectClause: Select<NSDictionary>, _ queryClauses: [QueryClause]) -> [[String: Any]]? {
|
public func queryAttributes<T>(_ from: From<T>, _ selectClause: Select<NSDictionary>, _ queryClauses: [QueryClause]) -> [[String: Any]]? {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ public /*abstract*/ class BaseDataTransaction {
|
|||||||
- parameter into: the `Into` clause indicating the destination `NSManagedObject` or `CoreStoreObject` entity type and the destination configuration
|
- parameter into: the `Into` clause indicating the destination `NSManagedObject` or `CoreStoreObject` entity type and the destination configuration
|
||||||
- returns: a new `NSManagedObject` or `CoreStoreObject` instance of the specified entity type.
|
- returns: a new `NSManagedObject` or `CoreStoreObject` instance of the specified entity type.
|
||||||
*/
|
*/
|
||||||
public func create<T: DynamicObject>(_ into: Into<T>) -> T {
|
public func create<T>(_ into: Into<T>) -> T {
|
||||||
|
|
||||||
let entityClass = into.entityClass
|
let entityClass = into.entityClass
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
@@ -141,7 +141,7 @@ public /*abstract*/ class BaseDataTransaction {
|
|||||||
- parameter objectID: the `NSManagedObjectID` for the object to be edited
|
- parameter objectID: the `NSManagedObjectID` for the object to be edited
|
||||||
- returns: an editable proxy for the specified `NSManagedObject`.
|
- returns: an editable proxy for the specified `NSManagedObject`.
|
||||||
*/
|
*/
|
||||||
public func edit<T: DynamicObject>(_ into: Into<T>, _ objectID: NSManagedObjectID) -> T? {
|
public func edit<T>(_ into: Into<T>, _ objectID: NSManagedObjectID) -> T? {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ public final class CSGroupBy: NSObject, CSQueryClause, CoreStoreObjectiveCType {
|
|||||||
The list of key path strings to group results with
|
The list of key path strings to group results with
|
||||||
*/
|
*/
|
||||||
@objc
|
@objc
|
||||||
public var keyPaths: [KeyPath] {
|
public var keyPaths: [RawKeyPath] {
|
||||||
|
|
||||||
return self.bridgeToSwift.keyPaths
|
return self.bridgeToSwift.keyPaths
|
||||||
}
|
}
|
||||||
@@ -52,7 +52,7 @@ public final class CSGroupBy: NSObject, CSQueryClause, CoreStoreObjectiveCType {
|
|||||||
- parameter keyPath: a key path string to group results with
|
- parameter keyPath: a key path string to group results with
|
||||||
*/
|
*/
|
||||||
@objc
|
@objc
|
||||||
public convenience init(keyPath: KeyPath) {
|
public convenience init(keyPath: RawKeyPath) {
|
||||||
|
|
||||||
self.init(GroupBy(keyPath))
|
self.init(GroupBy(keyPath))
|
||||||
}
|
}
|
||||||
@@ -63,7 +63,7 @@ public final class CSGroupBy: NSObject, CSQueryClause, CoreStoreObjectiveCType {
|
|||||||
- parameter keyPaths: a list of key path strings to group results with
|
- parameter keyPaths: a list of key path strings to group results with
|
||||||
*/
|
*/
|
||||||
@objc
|
@objc
|
||||||
public convenience init(keyPaths: [KeyPath]) {
|
public convenience init(keyPaths: [RawKeyPath]) {
|
||||||
|
|
||||||
self.init(GroupBy(keyPaths))
|
self.init(GroupBy(keyPaths))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ public final class CSSectionBy: NSObject, CoreStoreObjectiveCType {
|
|||||||
- returns: a `CSSectionBy` clause with the key path to use to group `CSListMonitor` objects into sections
|
- returns: a `CSSectionBy` clause with the key path to use to group `CSListMonitor` objects into sections
|
||||||
*/
|
*/
|
||||||
@objc
|
@objc
|
||||||
public static func keyPath(_ sectionKeyPath: KeyPath) -> CSSectionBy {
|
public static func keyPath(_ sectionKeyPath: RawKeyPath) -> CSSectionBy {
|
||||||
|
|
||||||
return self.init(SectionBy(sectionKeyPath))
|
return self.init(SectionBy(sectionKeyPath))
|
||||||
}
|
}
|
||||||
@@ -58,7 +58,7 @@ public final class CSSectionBy: NSObject, CoreStoreObjectiveCType {
|
|||||||
- returns: a `CSSectionBy` clause with the key path to use to group `CSListMonitor` objects into sections
|
- returns: a `CSSectionBy` clause with the key path to use to group `CSListMonitor` objects into sections
|
||||||
*/
|
*/
|
||||||
@objc
|
@objc
|
||||||
public static func keyPath(_ sectionKeyPath: KeyPath, sectionIndexTransformer: @escaping (_ sectionName: String?) -> String?) -> CSSectionBy {
|
public static func keyPath(_ sectionKeyPath: RawKeyPath, sectionIndexTransformer: @escaping (_ sectionName: String?) -> String?) -> CSSectionBy {
|
||||||
|
|
||||||
return self.init(SectionBy(sectionKeyPath, sectionIndexTransformer))
|
return self.init(SectionBy(sectionKeyPath, sectionIndexTransformer))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ public final class CSSelectTerm: NSObject, CoreStoreObjectiveCType {
|
|||||||
- parameter keyPath: the attribute name
|
- parameter keyPath: the attribute name
|
||||||
*/
|
*/
|
||||||
@objc
|
@objc
|
||||||
public convenience init(keyPath: KeyPath) {
|
public convenience init(keyPath: RawKeyPath) {
|
||||||
|
|
||||||
self.init(.attribute(keyPath))
|
self.init(.attribute(keyPath))
|
||||||
}
|
}
|
||||||
@@ -65,7 +65,7 @@ public final class CSSelectTerm: NSObject, CoreStoreObjectiveCType {
|
|||||||
- returns: a `CSSelectTerm` to a `CSSelect` clause for querying the average value of an attribute
|
- returns: a `CSSelectTerm` to a `CSSelect` clause for querying the average value of an attribute
|
||||||
*/
|
*/
|
||||||
@objc
|
@objc
|
||||||
public static func average(_ keyPath: KeyPath, as alias: KeyPath?) -> CSSelectTerm {
|
public static func average(_ keyPath: RawKeyPath, as alias: RawKeyPath?) -> CSSelectTerm {
|
||||||
|
|
||||||
return self.init(.average(keyPath, as: alias))
|
return self.init(.average(keyPath, as: alias))
|
||||||
}
|
}
|
||||||
@@ -82,7 +82,7 @@ public final class CSSelectTerm: NSObject, CoreStoreObjectiveCType {
|
|||||||
- returns: a `SelectTerm` to a `Select` clause for a count query
|
- returns: a `SelectTerm` to a `Select` clause for a count query
|
||||||
*/
|
*/
|
||||||
@objc
|
@objc
|
||||||
public static func count(_ keyPath: KeyPath, as alias: KeyPath?) -> CSSelectTerm {
|
public static func count(_ keyPath: RawKeyPath, as alias: RawKeyPath?) -> CSSelectTerm {
|
||||||
|
|
||||||
return self.init(.count(keyPath, as: alias))
|
return self.init(.count(keyPath, as: alias))
|
||||||
}
|
}
|
||||||
@@ -99,7 +99,7 @@ public final class CSSelectTerm: NSObject, CoreStoreObjectiveCType {
|
|||||||
- returns: a `CSSelectTerm` to a `CSSelect` clause for querying the maximum value for an attribute
|
- returns: a `CSSelectTerm` to a `CSSelect` clause for querying the maximum value for an attribute
|
||||||
*/
|
*/
|
||||||
@objc
|
@objc
|
||||||
public static func maximum(_ keyPath: KeyPath, as alias: KeyPath?) -> CSSelectTerm {
|
public static func maximum(_ keyPath: RawKeyPath, as alias: RawKeyPath?) -> CSSelectTerm {
|
||||||
|
|
||||||
return self.init(.maximum(keyPath, as: alias))
|
return self.init(.maximum(keyPath, as: alias))
|
||||||
}
|
}
|
||||||
@@ -116,7 +116,7 @@ public final class CSSelectTerm: NSObject, CoreStoreObjectiveCType {
|
|||||||
- returns: a `CSSelectTerm` to a `CSSelect` clause for querying the minimum value for an attribute
|
- returns: a `CSSelectTerm` to a `CSSelect` clause for querying the minimum value for an attribute
|
||||||
*/
|
*/
|
||||||
@objc
|
@objc
|
||||||
public static func minimum(_ keyPath: KeyPath, as alias: KeyPath?) -> CSSelectTerm {
|
public static func minimum(_ keyPath: RawKeyPath, as alias: RawKeyPath?) -> CSSelectTerm {
|
||||||
|
|
||||||
return self.init(.minimum(keyPath, as: alias))
|
return self.init(.minimum(keyPath, as: alias))
|
||||||
}
|
}
|
||||||
@@ -133,7 +133,7 @@ public final class CSSelectTerm: NSObject, CoreStoreObjectiveCType {
|
|||||||
- returns: a `CSSelectTerm` to a `CSSelect` clause for querying the sum value for an attribute
|
- returns: a `CSSelectTerm` to a `CSSelect` clause for querying the sum value for an attribute
|
||||||
*/
|
*/
|
||||||
@objc
|
@objc
|
||||||
public static func sum(_ keyPath: KeyPath, as alias: KeyPath?) -> CSSelectTerm {
|
public static func sum(_ keyPath: RawKeyPath, as alias: RawKeyPath?) -> CSSelectTerm {
|
||||||
|
|
||||||
return self.init(.sum(keyPath, as: alias))
|
return self.init(.sum(keyPath, as: alias))
|
||||||
}
|
}
|
||||||
@@ -150,7 +150,7 @@ public final class CSSelectTerm: NSObject, CoreStoreObjectiveCType {
|
|||||||
- returns: a `SelectTerm` to a `Select` clause for querying the sum value for an attribute
|
- returns: a `SelectTerm` to a `Select` clause for querying the sum value for an attribute
|
||||||
*/
|
*/
|
||||||
@objc
|
@objc
|
||||||
public static func objectIDAs(_ alias: KeyPath? = nil) -> CSSelectTerm {
|
public static func objectIDAs(_ alias: RawKeyPath? = nil) -> CSSelectTerm {
|
||||||
|
|
||||||
return self.init(.objectID(as: alias))
|
return self.init(.objectID(as: alias))
|
||||||
}
|
}
|
||||||
@@ -365,7 +365,7 @@ public final class CSSelect: NSObject {
|
|||||||
super.init()
|
super.init()
|
||||||
}
|
}
|
||||||
|
|
||||||
public init<T: SelectResultType>(_ swiftValue: Select<T>) {
|
public init<T>(_ swiftValue: Select<T>) {
|
||||||
|
|
||||||
self.attributeType = .undefinedAttributeType
|
self.attributeType = .undefinedAttributeType
|
||||||
self.selectTerms = swiftValue.selectTerms
|
self.selectTerms = swiftValue.selectTerms
|
||||||
|
|||||||
@@ -152,7 +152,7 @@ public final class CSSetupResult: NSObject {
|
|||||||
|
|
||||||
// MARK: CoreStoreObjectiveCType
|
// MARK: CoreStoreObjectiveCType
|
||||||
|
|
||||||
public required init<T: StorageInterface>(_ swiftValue: SetupResult<T>) where T: CoreStoreSwiftType, T.ObjectiveCType: CSStorageInterface {
|
public required init<T>(_ swiftValue: SetupResult<T>) where T: CoreStoreSwiftType, T.ObjectiveCType: CSStorageInterface {
|
||||||
|
|
||||||
switch swiftValue {
|
switch swiftValue {
|
||||||
|
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ public final class CSWhere: NSObject, CSFetchClause, CSQueryClause, CSDeleteClau
|
|||||||
- parameter value: the arguments for the `==` operator
|
- parameter value: the arguments for the `==` operator
|
||||||
*/
|
*/
|
||||||
@objc
|
@objc
|
||||||
public convenience init(keyPath: KeyPath, isEqualTo value: CoreDataNativeType?) {
|
public convenience init(keyPath: RawKeyPath, isEqualTo value: CoreDataNativeType?) {
|
||||||
|
|
||||||
self.init(value == nil || value is NSNull
|
self.init(value == nil || value is NSNull
|
||||||
? Where("\(keyPath) == nil")
|
? Where("\(keyPath) == nil")
|
||||||
@@ -99,7 +99,7 @@ public final class CSWhere: NSObject, CSFetchClause, CSQueryClause, CSDeleteClau
|
|||||||
- parameter list: the array to check membership of
|
- parameter list: the array to check membership of
|
||||||
*/
|
*/
|
||||||
@objc
|
@objc
|
||||||
public convenience init(keyPath: KeyPath, isMemberOf list: [CoreDataNativeType]) {
|
public convenience init(keyPath: RawKeyPath, isMemberOf list: [CoreDataNativeType]) {
|
||||||
|
|
||||||
self.init(Where("\(keyPath) IN %@", list as NSArray))
|
self.init(Where("\(keyPath) IN %@", list as NSArray))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ import CoreData
|
|||||||
*/
|
*/
|
||||||
public protocol FetchClause {
|
public protocol FetchClause {
|
||||||
|
|
||||||
func applyToFetchRequest<T: NSFetchRequestResult>(_ fetchRequest: NSFetchRequest<T>)
|
func applyToFetchRequest<T>(_ fetchRequest: NSFetchRequest<T>)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -45,7 +45,7 @@ public protocol FetchClause {
|
|||||||
*/
|
*/
|
||||||
public protocol QueryClause {
|
public protocol QueryClause {
|
||||||
|
|
||||||
func applyToFetchRequest<T: NSFetchRequestResult>(_ fetchRequest: NSFetchRequest<T>)
|
func applyToFetchRequest<T>(_ fetchRequest: NSFetchRequest<T>)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -56,5 +56,5 @@ public protocol QueryClause {
|
|||||||
*/
|
*/
|
||||||
public protocol DeleteClause {
|
public protocol DeleteClause {
|
||||||
|
|
||||||
func applyToFetchRequest<T: NSFetchRequestResult>(_ fetchRequest: NSFetchRequest<T>)
|
func applyToFetchRequest<T>(_ fetchRequest: NSFetchRequest<T>)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1215,6 +1215,8 @@ extension NSAttributeType: CoreStoreDebugStringConvertible {
|
|||||||
case .binaryDataAttributeType: return ".binaryDataAttributeType"
|
case .binaryDataAttributeType: return ".binaryDataAttributeType"
|
||||||
case .transformableAttributeType: return ".transformableAttributeType"
|
case .transformableAttributeType: return ".transformableAttributeType"
|
||||||
case .objectIDAttributeType: return ".objectIDAttributeType"
|
case .objectIDAttributeType: return ".objectIDAttributeType"
|
||||||
|
case .UUIDAttributeType: return ".UUIDAttributeType"
|
||||||
|
case .URIAttributeType: return ".URIAttributeType"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ public extension CoreStore {
|
|||||||
- parameter storage: the storage
|
- parameter storage: the storage
|
||||||
- parameter completion: the closure to be executed on the main queue when the process completes, either due to success or failure. The closure's `SetupResult` argument indicates the result. Note that the `StorageInterface` associated to the `SetupResult.success` may not always be the same instance as the parameter argument if a previous `StorageInterface` was already added at the same URL and with the same configuration.
|
- parameter completion: the closure to be executed on the main queue when the process completes, either due to success or failure. The closure's `SetupResult` argument indicates the result. Note that the `StorageInterface` associated to the `SetupResult.success` may not always be the same instance as the parameter argument if a previous `StorageInterface` was already added at the same URL and with the same configuration.
|
||||||
*/
|
*/
|
||||||
public static func addStorage<T: StorageInterface>(_ storage: T, completion: @escaping (SetupResult<T>) -> Void) {
|
public static func addStorage<T>(_ storage: T, completion: @escaping (SetupResult<T>) -> Void) {
|
||||||
|
|
||||||
self.defaultStack.addStorage(storage, completion: completion)
|
self.defaultStack.addStorage(storage, completion: completion)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ public extension CoreStore {
|
|||||||
- parameter object: the `DynamicObject` to observe changes from
|
- parameter object: the `DynamicObject` to observe changes from
|
||||||
- returns: a `ObjectMonitor` that monitors changes to `object`
|
- returns: a `ObjectMonitor` that monitors changes to `object`
|
||||||
*/
|
*/
|
||||||
public static func monitorObject<T: DynamicObject>(_ object: T) -> ObjectMonitor<T> {
|
public static func monitorObject<T>(_ object: T) -> ObjectMonitor<T> {
|
||||||
|
|
||||||
return self.defaultStack.monitorObject(object)
|
return self.defaultStack.monitorObject(object)
|
||||||
}
|
}
|
||||||
@@ -50,7 +50,7 @@ public extension CoreStore {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: a `ListMonitor` instance that monitors changes to the list
|
- returns: a `ListMonitor` instance that monitors changes to the list
|
||||||
*/
|
*/
|
||||||
public static func monitorList<T: DynamicObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> ListMonitor<T> {
|
public static func monitorList<T>(_ from: From<T>, _ fetchClauses: FetchClause...) -> ListMonitor<T> {
|
||||||
|
|
||||||
return self.defaultStack.monitorList(from, fetchClauses)
|
return self.defaultStack.monitorList(from, fetchClauses)
|
||||||
}
|
}
|
||||||
@@ -62,7 +62,7 @@ public extension CoreStore {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: a `ListMonitor` instance that monitors changes to the list
|
- returns: a `ListMonitor` instance that monitors changes to the list
|
||||||
*/
|
*/
|
||||||
public static func monitorList<T: DynamicObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> ListMonitor<T> {
|
public static func monitorList<T>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> ListMonitor<T> {
|
||||||
|
|
||||||
return self.defaultStack.monitorList(from, fetchClauses)
|
return self.defaultStack.monitorList(from, fetchClauses)
|
||||||
}
|
}
|
||||||
@@ -74,7 +74,7 @@ public extension CoreStore {
|
|||||||
- parameter from: a `From` clause indicating the entity type
|
- parameter from: a `From` clause indicating the entity type
|
||||||
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
*/
|
*/
|
||||||
public static func monitorList<T: DynamicObject>(createAsynchronously: @escaping (ListMonitor<T>) -> Void, _ from: From<T>, _ fetchClauses: FetchClause...) {
|
public static func monitorList<T>(createAsynchronously: @escaping (ListMonitor<T>) -> Void, _ from: From<T>, _ fetchClauses: FetchClause...) {
|
||||||
|
|
||||||
self.defaultStack.monitorList(createAsynchronously: createAsynchronously, from, fetchClauses)
|
self.defaultStack.monitorList(createAsynchronously: createAsynchronously, from, fetchClauses)
|
||||||
}
|
}
|
||||||
@@ -86,7 +86,7 @@ public extension CoreStore {
|
|||||||
- parameter from: a `From` clause indicating the entity type
|
- parameter from: a `From` clause indicating the entity type
|
||||||
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
*/
|
*/
|
||||||
public static func monitorList<T: DynamicObject>(createAsynchronously: @escaping (ListMonitor<T>) -> Void, _ from: From<T>, _ fetchClauses: [FetchClause]) {
|
public static func monitorList<T>(createAsynchronously: @escaping (ListMonitor<T>) -> Void, _ from: From<T>, _ fetchClauses: [FetchClause]) {
|
||||||
|
|
||||||
self.defaultStack.monitorList(createAsynchronously: createAsynchronously, from, fetchClauses)
|
self.defaultStack.monitorList(createAsynchronously: createAsynchronously, from, fetchClauses)
|
||||||
}
|
}
|
||||||
@@ -99,7 +99,7 @@ public extension CoreStore {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: a `ListMonitor` instance that monitors changes to the list
|
- returns: a `ListMonitor` instance that monitors changes to the list
|
||||||
*/
|
*/
|
||||||
public static func monitorSectionedList<T: DynamicObject>(_ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) -> ListMonitor<T> {
|
public static func monitorSectionedList<T>(_ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) -> ListMonitor<T> {
|
||||||
|
|
||||||
return self.defaultStack.monitorSectionedList(from, sectionBy, fetchClauses)
|
return self.defaultStack.monitorSectionedList(from, sectionBy, fetchClauses)
|
||||||
}
|
}
|
||||||
@@ -112,7 +112,7 @@ public extension CoreStore {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: a `ListMonitor` instance that monitors changes to the list
|
- returns: a `ListMonitor` instance that monitors changes to the list
|
||||||
*/
|
*/
|
||||||
public static func monitorSectionedList<T: DynamicObject>(_ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) -> ListMonitor<T> {
|
public static func monitorSectionedList<T>(_ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) -> ListMonitor<T> {
|
||||||
|
|
||||||
return self.defaultStack.monitorSectionedList(from, sectionBy, fetchClauses)
|
return self.defaultStack.monitorSectionedList(from, sectionBy, fetchClauses)
|
||||||
}
|
}
|
||||||
@@ -125,7 +125,7 @@ public extension CoreStore {
|
|||||||
- parameter sectionBy: a `SectionBy` clause indicating the keyPath for the attribute to use when sorting the list into sections.
|
- parameter sectionBy: a `SectionBy` clause indicating the keyPath for the attribute to use when sorting the list into sections.
|
||||||
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
*/
|
*/
|
||||||
public static func monitorSectionedList<T: DynamicObject>(createAsynchronously: @escaping (ListMonitor<T>) -> Void, _ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) {
|
public static func monitorSectionedList<T>(createAsynchronously: @escaping (ListMonitor<T>) -> Void, _ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) {
|
||||||
|
|
||||||
self.defaultStack.monitorSectionedList(createAsynchronously: createAsynchronously, from, sectionBy, fetchClauses)
|
self.defaultStack.monitorSectionedList(createAsynchronously: createAsynchronously, from, sectionBy, fetchClauses)
|
||||||
}
|
}
|
||||||
@@ -138,7 +138,7 @@ public extension CoreStore {
|
|||||||
- parameter sectionBy: a `SectionBy` clause indicating the keyPath for the attribute to use when sorting the list into sections.
|
- parameter sectionBy: a `SectionBy` clause indicating the keyPath for the attribute to use when sorting the list into sections.
|
||||||
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
*/
|
*/
|
||||||
public static func monitorSectionedList<T: DynamicObject>(createAsynchronously: @escaping (ListMonitor<T>) -> Void, _ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) {
|
public static func monitorSectionedList<T>(createAsynchronously: @escaping (ListMonitor<T>) -> Void, _ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) {
|
||||||
|
|
||||||
self.defaultStack.monitorSectionedList(createAsynchronously: createAsynchronously, from, sectionBy, fetchClauses)
|
self.defaultStack.monitorSectionedList(createAsynchronously: createAsynchronously, from, sectionBy, fetchClauses)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ public extension CoreStore {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: the first `DynamicObject` instance that satisfies the specified `FetchClause`s
|
- returns: the first `DynamicObject` instance that satisfies the specified `FetchClause`s
|
||||||
*/
|
*/
|
||||||
public static func fetchOne<T: DynamicObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> T? {
|
public static func fetchOne<T>(_ from: From<T>, _ fetchClauses: FetchClause...) -> T? {
|
||||||
|
|
||||||
return self.defaultStack.fetchOne(from, fetchClauses)
|
return self.defaultStack.fetchOne(from, fetchClauses)
|
||||||
}
|
}
|
||||||
@@ -94,7 +94,7 @@ public extension CoreStore {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: the first `DynamicObject` instance that satisfies the specified `FetchClause`s
|
- returns: the first `DynamicObject` instance that satisfies the specified `FetchClause`s
|
||||||
*/
|
*/
|
||||||
public static func fetchOne<T: DynamicObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> T? {
|
public static func fetchOne<T>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> T? {
|
||||||
|
|
||||||
return self.defaultStack.fetchOne(from, fetchClauses)
|
return self.defaultStack.fetchOne(from, fetchClauses)
|
||||||
}
|
}
|
||||||
@@ -106,7 +106,7 @@ public extension CoreStore {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: all `DynamicObject` instances that satisfy the specified `FetchClause`s
|
- returns: all `DynamicObject` instances that satisfy the specified `FetchClause`s
|
||||||
*/
|
*/
|
||||||
public static func fetchAll<T: DynamicObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> [T]? {
|
public static func fetchAll<T>(_ from: From<T>, _ fetchClauses: FetchClause...) -> [T]? {
|
||||||
|
|
||||||
return self.defaultStack.fetchAll(from, fetchClauses)
|
return self.defaultStack.fetchAll(from, fetchClauses)
|
||||||
}
|
}
|
||||||
@@ -118,7 +118,7 @@ public extension CoreStore {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: all `DynamicObject` instances that satisfy the specified `FetchClause`s
|
- returns: all `DynamicObject` instances that satisfy the specified `FetchClause`s
|
||||||
*/
|
*/
|
||||||
public static func fetchAll<T: DynamicObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> [T]? {
|
public static func fetchAll<T>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> [T]? {
|
||||||
|
|
||||||
return self.defaultStack.fetchAll(from, fetchClauses)
|
return self.defaultStack.fetchAll(from, fetchClauses)
|
||||||
}
|
}
|
||||||
@@ -130,7 +130,7 @@ public extension CoreStore {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: the number `DynamicObject`s that satisfy the specified `FetchClause`s
|
- returns: the number `DynamicObject`s that satisfy the specified `FetchClause`s
|
||||||
*/
|
*/
|
||||||
public static func fetchCount<T: DynamicObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> Int? {
|
public static func fetchCount<T>(_ from: From<T>, _ fetchClauses: FetchClause...) -> Int? {
|
||||||
|
|
||||||
return self.defaultStack.fetchCount(from, fetchClauses)
|
return self.defaultStack.fetchCount(from, fetchClauses)
|
||||||
}
|
}
|
||||||
@@ -142,7 +142,7 @@ public extension CoreStore {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: the number `DynamicObject`s that satisfy the specified `FetchClause`s
|
- returns: the number `DynamicObject`s that satisfy the specified `FetchClause`s
|
||||||
*/
|
*/
|
||||||
public static func fetchCount<T: DynamicObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> Int? {
|
public static func fetchCount<T>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> Int? {
|
||||||
|
|
||||||
return self.defaultStack.fetchCount(from, fetchClauses)
|
return self.defaultStack.fetchCount(from, fetchClauses)
|
||||||
}
|
}
|
||||||
@@ -154,7 +154,7 @@ public extension CoreStore {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s
|
- returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s
|
||||||
*/
|
*/
|
||||||
public static func fetchObjectID<T: DynamicObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> NSManagedObjectID? {
|
public static func fetchObjectID<T>(_ from: From<T>, _ fetchClauses: FetchClause...) -> NSManagedObjectID? {
|
||||||
|
|
||||||
return self.defaultStack.fetchObjectID(from, fetchClauses)
|
return self.defaultStack.fetchObjectID(from, fetchClauses)
|
||||||
}
|
}
|
||||||
@@ -166,7 +166,7 @@ public extension CoreStore {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s
|
- returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s
|
||||||
*/
|
*/
|
||||||
public static func fetchObjectID<T: DynamicObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> NSManagedObjectID? {
|
public static func fetchObjectID<T>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> NSManagedObjectID? {
|
||||||
|
|
||||||
return self.defaultStack.fetchObjectID(from, fetchClauses)
|
return self.defaultStack.fetchObjectID(from, fetchClauses)
|
||||||
}
|
}
|
||||||
@@ -178,7 +178,7 @@ public extension CoreStore {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s
|
- returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s
|
||||||
*/
|
*/
|
||||||
public static func fetchObjectIDs<T: DynamicObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> [NSManagedObjectID]? {
|
public static func fetchObjectIDs<T>(_ from: From<T>, _ fetchClauses: FetchClause...) -> [NSManagedObjectID]? {
|
||||||
|
|
||||||
return self.defaultStack.fetchObjectIDs(from, fetchClauses)
|
return self.defaultStack.fetchObjectIDs(from, fetchClauses)
|
||||||
}
|
}
|
||||||
@@ -190,7 +190,7 @@ public extension CoreStore {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s
|
- returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s
|
||||||
*/
|
*/
|
||||||
public static func fetchObjectIDs<T: DynamicObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> [NSManagedObjectID]? {
|
public static func fetchObjectIDs<T>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> [NSManagedObjectID]? {
|
||||||
|
|
||||||
return self.defaultStack.fetchObjectIDs(from, fetchClauses)
|
return self.defaultStack.fetchObjectIDs(from, fetchClauses)
|
||||||
}
|
}
|
||||||
@@ -205,7 +205,7 @@ public extension CoreStore {
|
|||||||
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
||||||
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
||||||
*/
|
*/
|
||||||
public static func queryValue<T: DynamicObject, U: QueryableAttributeType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: QueryClause...) -> U? {
|
public static func queryValue<T, U: QueryableAttributeType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: QueryClause...) -> U? {
|
||||||
|
|
||||||
return self.defaultStack.queryValue(from, selectClause, queryClauses)
|
return self.defaultStack.queryValue(from, selectClause, queryClauses)
|
||||||
}
|
}
|
||||||
@@ -220,7 +220,7 @@ public extension CoreStore {
|
|||||||
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
||||||
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
||||||
*/
|
*/
|
||||||
public static func queryValue<T: DynamicObject, U: QueryableAttributeType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: [QueryClause]) -> U? {
|
public static func queryValue<T, U: QueryableAttributeType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: [QueryClause]) -> U? {
|
||||||
|
|
||||||
return self.defaultStack.queryValue(from, selectClause, queryClauses)
|
return self.defaultStack.queryValue(from, selectClause, queryClauses)
|
||||||
}
|
}
|
||||||
@@ -235,7 +235,7 @@ public extension CoreStore {
|
|||||||
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
||||||
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
||||||
*/
|
*/
|
||||||
public static func queryAttributes<T: DynamicObject>(_ from: From<T>, _ selectClause: Select<NSDictionary>, _ queryClauses: QueryClause...) -> [[String: Any]]? {
|
public static func queryAttributes<T>(_ from: From<T>, _ selectClause: Select<NSDictionary>, _ queryClauses: QueryClause...) -> [[String: Any]]? {
|
||||||
|
|
||||||
return self.defaultStack.queryAttributes(from, selectClause, queryClauses)
|
return self.defaultStack.queryAttributes(from, selectClause, queryClauses)
|
||||||
}
|
}
|
||||||
@@ -250,7 +250,7 @@ public extension CoreStore {
|
|||||||
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
||||||
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
||||||
*/
|
*/
|
||||||
public static func queryAttributes<T: DynamicObject>(_ from: From<T>, _ selectClause: Select<NSDictionary>, _ queryClauses: [QueryClause]) -> [[String: Any]]? {
|
public static func queryAttributes<T>(_ from: From<T>, _ selectClause: Select<NSDictionary>, _ queryClauses: [QueryClause]) -> [[String: Any]]? {
|
||||||
|
|
||||||
return self.defaultStack.queryAttributes(from, selectClause, queryClauses)
|
return self.defaultStack.queryAttributes(from, selectClause, queryClauses)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,7 @@
|
|||||||
#define CORESTORE_RETURNS_RETAINED __attribute__((ns_returns_retained))
|
#define CORESTORE_RETURNS_RETAINED __attribute__((ns_returns_retained))
|
||||||
|
|
||||||
|
|
||||||
#pragma mark - KeyPath Utilities
|
#pragma mark - RawKeyPath Utilities
|
||||||
|
|
||||||
#define CSKeyPath(type, property) ({ \
|
#define CSKeyPath(type, property) ({ \
|
||||||
type *_je_keypath_dummy __attribute__((unused)); \
|
type *_je_keypath_dummy __attribute__((unused)); \
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ internal extension CoreStoreFetchRequest {
|
|||||||
// MARK: Internal
|
// MARK: Internal
|
||||||
|
|
||||||
@nonobjc @inline(__always)
|
@nonobjc @inline(__always)
|
||||||
internal func dynamicCast<U: NSFetchRequestResult>() -> NSFetchRequest<U> {
|
internal func dynamicCast<U>() -> NSFetchRequest<U> {
|
||||||
|
|
||||||
return unsafeBitCast(self, to: NSFetchRequest<U>.self)
|
return unsafeBitCast(self, to: NSFetchRequest<U>.self)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ internal final class CoreStoreFetchedResultsController: NSFetchedResultsControll
|
|||||||
// MARK: Internal
|
// MARK: Internal
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
internal convenience init<T: DynamicObject>(dataStack: DataStack, fetchRequest: NSFetchRequest<NSManagedObject>, from: From<T>, sectionBy: SectionBy? = nil, applyFetchClauses: @escaping (_ fetchRequest: NSFetchRequest<NSManagedObject>) -> Void) {
|
internal convenience init<T>(dataStack: DataStack, fetchRequest: NSFetchRequest<NSManagedObject>, from: From<T>, sectionBy: SectionBy? = nil, applyFetchClauses: @escaping (_ fetchRequest: NSFetchRequest<NSManagedObject>) -> Void) {
|
||||||
|
|
||||||
self.init(
|
self.init(
|
||||||
context: dataStack.mainContext,
|
context: dataStack.mainContext,
|
||||||
@@ -47,7 +47,7 @@ internal final class CoreStoreFetchedResultsController: NSFetchedResultsControll
|
|||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
internal init<T: DynamicObject>(context: NSManagedObjectContext, fetchRequest: NSFetchRequest<NSManagedObject>, from: From<T>, sectionBy: SectionBy? = nil, applyFetchClauses: @escaping (_ fetchRequest: NSFetchRequest<NSManagedObject>) -> Void) {
|
internal init<T>(context: NSManagedObjectContext, fetchRequest: NSFetchRequest<NSManagedObject>, from: From<T>, sectionBy: SectionBy? = nil, applyFetchClauses: @escaping (_ fetchRequest: NSFetchRequest<NSManagedObject>) -> Void) {
|
||||||
|
|
||||||
_ = from.applyToFetchRequest(
|
_ = from.applyToFetchRequest(
|
||||||
fetchRequest,
|
fetchRequest,
|
||||||
@@ -83,7 +83,7 @@ internal final class CoreStoreFetchedResultsController: NSFetchedResultsControll
|
|||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
internal func dynamicCast<U: NSFetchRequestResult>() -> NSFetchedResultsController<U> {
|
internal func dynamicCast<U>() -> NSFetchedResultsController<U> {
|
||||||
|
|
||||||
return unsafeBitCast(self, to: NSFetchedResultsController<U>.self)
|
return unsafeBitCast(self, to: NSFetchedResultsController<U>.self)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,12 +47,6 @@ public enum LogLevel {
|
|||||||
*/
|
*/
|
||||||
public protocol CoreStoreLogger {
|
public protocol CoreStoreLogger {
|
||||||
|
|
||||||
/**
|
|
||||||
When `true`, all `NSManagedObject` attribute and relationship access will raise an assertion when executed on the wrong transaction/datastack queue. Defaults to `false` if not implemented.
|
|
||||||
*/
|
|
||||||
// TODO: test before release (rolled back)
|
|
||||||
// var enableObjectConcurrencyDebugging: Bool { get set }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Handles log messages sent by the `CoreStore` framework.
|
Handles log messages sent by the `CoreStore` framework.
|
||||||
|
|
||||||
@@ -100,13 +94,6 @@ public protocol CoreStoreLogger {
|
|||||||
|
|
||||||
extension CoreStoreLogger {
|
extension CoreStoreLogger {
|
||||||
|
|
||||||
// TODO: test before release (rolled back)
|
|
||||||
// public var enableObjectConcurrencyDebugging: Bool {
|
|
||||||
//
|
|
||||||
// get { return false }
|
|
||||||
// set {}
|
|
||||||
// }
|
|
||||||
|
|
||||||
public func abort(_ message: String, fileName: StaticString, lineNumber: Int, functionName: StaticString) {
|
public func abort(_ message: String, fileName: StaticString, lineNumber: Int, functionName: StaticString) {
|
||||||
|
|
||||||
Swift.fatalError(message, file: fileName, line: UInt(lineNumber))
|
Swift.fatalError(message, file: fileName, line: UInt(lineNumber))
|
||||||
|
|||||||
@@ -30,5 +30,5 @@ import CoreData
|
|||||||
private enum Static {
|
private enum Static {
|
||||||
|
|
||||||
static let queue = DispatchQueue.concurrent("com.coreStore.coreStoreManagerObjectBarrierQueue")
|
static let queue = DispatchQueue.concurrent("com.coreStore.coreStoreManagerObjectBarrierQueue")
|
||||||
static var cache: [ObjectIdentifier: [KeyPath: Set<KeyPath>]] = [:]
|
static var cache: [ObjectIdentifier: [RawKeyPath: Set<RawKeyPath>]] = [:]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ public extension DynamicObject where Self: CoreStoreObject {
|
|||||||
let keyPath: String = Person.keyPath { $0.nickname }
|
let keyPath: String = Person.keyPath { $0.nickname }
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
public static func keyPath<O: CoreStoreObject, V: ImportableAttributeType>(_ attribute: (Self) -> ValueContainer<O>.Required<V>) -> String {
|
public static func keyPath<O, V>(_ attribute: (Self) -> ValueContainer<O>.Required<V>) -> String {
|
||||||
|
|
||||||
return attribute(self.meta).keyPath
|
return attribute(self.meta).keyPath
|
||||||
}
|
}
|
||||||
@@ -48,7 +48,7 @@ public extension DynamicObject where Self: CoreStoreObject {
|
|||||||
let keyPath: String = Person.keyPath { $0.nickname }
|
let keyPath: String = Person.keyPath { $0.nickname }
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
public static func keyPath<O: CoreStoreObject, V: ImportableAttributeType>(_ attribute: (Self) -> ValueContainer<O>.Optional<V>) -> String {
|
public static func keyPath<O, V>(_ attribute: (Self) -> ValueContainer<O>.Optional<V>) -> String {
|
||||||
|
|
||||||
return attribute(self.meta).keyPath
|
return attribute(self.meta).keyPath
|
||||||
}
|
}
|
||||||
@@ -59,7 +59,7 @@ public extension DynamicObject where Self: CoreStoreObject {
|
|||||||
let keyPath: String = Person.keyPath { $0.pets }
|
let keyPath: String = Person.keyPath { $0.pets }
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
public static func keyPath<O: CoreStoreObject, D: CoreStoreObject>(_ relationship: (Self) -> RelationshipContainer<O>.ToOne<D>) -> String {
|
public static func keyPath<O, D>(_ relationship: (Self) -> RelationshipContainer<O>.ToOne<D>) -> String {
|
||||||
|
|
||||||
return relationship(self.meta).keyPath
|
return relationship(self.meta).keyPath
|
||||||
}
|
}
|
||||||
@@ -70,7 +70,7 @@ public extension DynamicObject where Self: CoreStoreObject {
|
|||||||
let keyPath: String = Person.keyPath { $0.pets }
|
let keyPath: String = Person.keyPath { $0.pets }
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
public static func keyPath<O: CoreStoreObject, D: CoreStoreObject>(_ relationship: (Self) -> RelationshipContainer<O>.ToManyOrdered<D>) -> String {
|
public static func keyPath<O, D>(_ relationship: (Self) -> RelationshipContainer<O>.ToManyOrdered<D>) -> String {
|
||||||
|
|
||||||
return relationship(self.meta).keyPath
|
return relationship(self.meta).keyPath
|
||||||
}
|
}
|
||||||
@@ -81,7 +81,7 @@ public extension DynamicObject where Self: CoreStoreObject {
|
|||||||
let keyPath: String = Person.keyPath { $0.pets }
|
let keyPath: String = Person.keyPath { $0.pets }
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
public static func keyPath<O: CoreStoreObject, D: CoreStoreObject>(_ relationship: (Self) -> RelationshipContainer<O>.ToManyUnordered<D>) -> String {
|
public static func keyPath<O, D>(_ relationship: (Self) -> RelationshipContainer<O>.ToManyUnordered<D>) -> String {
|
||||||
|
|
||||||
return relationship(self.meta).keyPath
|
return relationship(self.meta).keyPath
|
||||||
}
|
}
|
||||||
@@ -103,7 +103,7 @@ public extension DynamicObject where Self: CoreStoreObject {
|
|||||||
let person = CoreStore.fetchAll(From<Person>(), Person.orderBy(ascending: { $0.age }))
|
let person = CoreStore.fetchAll(From<Person>(), Person.orderBy(ascending: { $0.age }))
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
public static func orderBy<O: CoreStoreObject, V: ImportableAttributeType>(ascending attribute: (Self) -> ValueContainer<O>.Required<V>) -> OrderBy {
|
public static func orderBy<O, V>(ascending attribute: (Self) -> ValueContainer<O>.Required<V>) -> OrderBy {
|
||||||
|
|
||||||
return OrderBy(.ascending(attribute(self.meta).keyPath))
|
return OrderBy(.ascending(attribute(self.meta).keyPath))
|
||||||
}
|
}
|
||||||
@@ -114,7 +114,7 @@ public extension DynamicObject where Self: CoreStoreObject {
|
|||||||
let person = CoreStore.fetchAll(From<Person>(), Person.orderBy(ascending: { $0.age }))
|
let person = CoreStore.fetchAll(From<Person>(), Person.orderBy(ascending: { $0.age }))
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
public static func orderBy<O: CoreStoreObject, V: ImportableAttributeType>(ascending attribute: (Self) -> ValueContainer<O>.Optional<V>) -> OrderBy {
|
public static func orderBy<O, V>(ascending attribute: (Self) -> ValueContainer<O>.Optional<V>) -> OrderBy {
|
||||||
|
|
||||||
return OrderBy(.ascending(attribute(self.meta).keyPath))
|
return OrderBy(.ascending(attribute(self.meta).keyPath))
|
||||||
}
|
}
|
||||||
@@ -125,7 +125,7 @@ public extension DynamicObject where Self: CoreStoreObject {
|
|||||||
let person = CoreStore.fetchAll(From<Person>(), Person.orderBy(descending: { $0.age }))
|
let person = CoreStore.fetchAll(From<Person>(), Person.orderBy(descending: { $0.age }))
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
public static func orderBy<O: CoreStoreObject, V: ImportableAttributeType>(descending attribute: (Self) -> ValueContainer<O>.Required<V>) -> OrderBy {
|
public static func orderBy<O, V>(descending attribute: (Self) -> ValueContainer<O>.Required<V>) -> OrderBy {
|
||||||
|
|
||||||
return OrderBy(.descending(attribute(self.meta).keyPath))
|
return OrderBy(.descending(attribute(self.meta).keyPath))
|
||||||
}
|
}
|
||||||
@@ -136,7 +136,7 @@ public extension DynamicObject where Self: CoreStoreObject {
|
|||||||
let person = CoreStore.fetchAll(From<Person>(), Person.orderBy(descending: { $0.age }))
|
let person = CoreStore.fetchAll(From<Person>(), Person.orderBy(descending: { $0.age }))
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
public static func orderBy<O: CoreStoreObject, V: ImportableAttributeType>(descending attribute: (Self) -> ValueContainer<O>.Optional<V>) -> OrderBy {
|
public static func orderBy<O, V>(descending attribute: (Self) -> ValueContainer<O>.Optional<V>) -> OrderBy {
|
||||||
|
|
||||||
return OrderBy(.descending(attribute(self.meta).keyPath))
|
return OrderBy(.descending(attribute(self.meta).keyPath))
|
||||||
}
|
}
|
||||||
@@ -145,13 +145,13 @@ public extension DynamicObject where Self: CoreStoreObject {
|
|||||||
// MARK: Deprecated
|
// MARK: Deprecated
|
||||||
|
|
||||||
@available(*, deprecated, renamed: "orderBy(ascending:)")
|
@available(*, deprecated, renamed: "orderBy(ascending:)")
|
||||||
public static func ascending<O: CoreStoreObject, V: ImportableAttributeType>(_ attribute: (Self) -> ValueContainer<O>.Optional<V>) -> OrderBy {
|
public static func ascending<O, V>(_ attribute: (Self) -> ValueContainer<O>.Optional<V>) -> OrderBy {
|
||||||
|
|
||||||
return OrderBy(.ascending(attribute(self.meta).keyPath))
|
return OrderBy(.ascending(attribute(self.meta).keyPath))
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(*, deprecated, renamed: "orderBy(descending:)")
|
@available(*, deprecated, renamed: "orderBy(descending:)")
|
||||||
public static func descending<O: CoreStoreObject, V: ImportableAttributeType>(_ attribute: (Self) -> ValueContainer<O>.Optional<V>) -> OrderBy {
|
public static func descending<O, V>(_ attribute: (Self) -> ValueContainer<O>.Optional<V>) -> OrderBy {
|
||||||
|
|
||||||
return OrderBy(.descending(attribute(self.meta).keyPath))
|
return OrderBy(.descending(attribute(self.meta).keyPath))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,13 +33,13 @@ import Foundation
|
|||||||
The `CoreStoreObject` is an abstract class for creating CoreStore-managed objects that are more type-safe and more convenient than `NSManagedObject` subclasses. The model entities for `CoreStoreObject` subclasses are inferred from the Swift declaration themselves; no .xcdatamodeld files are needed. To declare persisted attributes and relationships for the `CoreStoreObject` subclass, declare properties of type `Value.Required<T>`, `Value.Optional<T>` for values, or `Relationship.ToOne<T>`, `Relationship.ToManyOrdered<T>`, `Relationship.ToManyUnordered<T>` for relationships.
|
The `CoreStoreObject` is an abstract class for creating CoreStore-managed objects that are more type-safe and more convenient than `NSManagedObject` subclasses. The model entities for `CoreStoreObject` subclasses are inferred from the Swift declaration themselves; no .xcdatamodeld files are needed. To declare persisted attributes and relationships for the `CoreStoreObject` subclass, declare properties of type `Value.Required<T>`, `Value.Optional<T>` for values, or `Relationship.ToOne<T>`, `Relationship.ToManyOrdered<T>`, `Relationship.ToManyUnordered<T>` for relationships.
|
||||||
```
|
```
|
||||||
class Animal: CoreStoreObject {
|
class Animal: CoreStoreObject {
|
||||||
let species = Value.Required<String>("species")
|
let species = Value.Required<String>("species", initial: "")
|
||||||
let nickname = Value.Optional<String>("nickname")
|
let nickname = Value.Optional<String>("nickname")
|
||||||
let master = Relationship.ToOne<Person>("master")
|
let master = Relationship.ToOne<Person>("master")
|
||||||
}
|
}
|
||||||
|
|
||||||
class Person: CoreStoreObject {
|
class Person: CoreStoreObject {
|
||||||
let name = Value.Required<String>("name")
|
let name = Value.Required<String>("name", initial: "")
|
||||||
let pet = Relationship.ToOne<Animal>("pet", inverse: { $0.master })
|
let pet = Relationship.ToOne<Animal>("pet", inverse: { $0.master })
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -141,6 +141,9 @@ open /*abstract*/ class CoreStoreObject: DynamicObject, Hashable {
|
|||||||
|
|
||||||
public extension DynamicObject where Self: CoreStoreObject {
|
public extension DynamicObject where Self: CoreStoreObject {
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns the `PartialObject` instance for the object, which acts as a fast, type-safe KVC interface for `CoreStoreObject`.
|
||||||
|
*/
|
||||||
public func partialObject() -> PartialObject<Self> {
|
public func partialObject() -> PartialObject<Self> {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
|
|||||||
@@ -33,13 +33,13 @@ import Foundation
|
|||||||
The `CoreStoreSchema` describes models written for `CoreStoreObject` Swift class declarations for a particular model version. `CoreStoreObject` entities for a model version should be added to `CoreStoreSchema` instance.
|
The `CoreStoreSchema` describes models written for `CoreStoreObject` Swift class declarations for a particular model version. `CoreStoreObject` entities for a model version should be added to `CoreStoreSchema` instance.
|
||||||
```
|
```
|
||||||
class Animal: CoreStoreObject {
|
class Animal: CoreStoreObject {
|
||||||
let species = Value.Required<String>("species")
|
let species = Value.Required<String>("species", initial: "")
|
||||||
let nickname = Value.Optional<String>("nickname")
|
let nickname = Value.Optional<String>("nickname")
|
||||||
let master = Relationship.ToOne<Person>("master")
|
let master = Relationship.ToOne<Person>("master")
|
||||||
}
|
}
|
||||||
|
|
||||||
class Person: CoreStoreObject {
|
class Person: CoreStoreObject {
|
||||||
let name = Value.Required<String>("name")
|
let name = Value.Required<String>("name", initial: "")
|
||||||
let pet = Relationship.ToOne<Animal>("pet", inverse: { $0.master })
|
let pet = Relationship.ToOne<Animal>("pet", inverse: { $0.master })
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,13 +66,13 @@ public final class CoreStoreSchema: DynamicSchema {
|
|||||||
Initializes a `CoreStoreSchema`. Using this initializer only if the entities don't need to be assigned to particular "Configurations". To use multiple configurations (for example, to separate entities in different `StorageInterface`s), use the `init(modelVersion:entitiesByConfiguration:versionLock:)` initializer.
|
Initializes a `CoreStoreSchema`. Using this initializer only if the entities don't need to be assigned to particular "Configurations". To use multiple configurations (for example, to separate entities in different `StorageInterface`s), use the `init(modelVersion:entitiesByConfiguration:versionLock:)` initializer.
|
||||||
```
|
```
|
||||||
class Animal: CoreStoreObject {
|
class Animal: CoreStoreObject {
|
||||||
let species = Value.Required<String>("species")
|
let species = Value.Required<String>("species", initial: "")
|
||||||
let nickname = Value.Optional<String>("nickname")
|
let nickname = Value.Optional<String>("nickname")
|
||||||
let master = Relationship.ToOne<Person>("master")
|
let master = Relationship.ToOne<Person>("master")
|
||||||
}
|
}
|
||||||
|
|
||||||
class Person: CoreStoreObject {
|
class Person: CoreStoreObject {
|
||||||
let name = Value.Required<String>("name")
|
let name = Value.Required<String>("name", initial: "")
|
||||||
let pet = Relationship.ToOne<Animal>("pet", inverse: { $0.master })
|
let pet = Relationship.ToOne<Animal>("pet", inverse: { $0.master })
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,12 +112,12 @@ public final class CoreStoreSchema: DynamicSchema {
|
|||||||
Initializes a `CoreStoreSchema`. Using this initializer if multiple "Configurations" (for example, to separate entities in different `StorageInterface`s) are needed. To add an entity only to the default configuration, assign an empty set to its configurations list. Note that regardless of the set configurations, all entities will be added to the default configuration.
|
Initializes a `CoreStoreSchema`. Using this initializer if multiple "Configurations" (for example, to separate entities in different `StorageInterface`s) are needed. To add an entity only to the default configuration, assign an empty set to its configurations list. Note that regardless of the set configurations, all entities will be added to the default configuration.
|
||||||
```
|
```
|
||||||
class Animal: CoreStoreObject {
|
class Animal: CoreStoreObject {
|
||||||
let species = Value.Required<String>("species")
|
let species = Value.Required<String>("species", initial: "")
|
||||||
let nickname = Value.Optional<String>("nickname")
|
let nickname = Value.Optional<String>("nickname")
|
||||||
}
|
}
|
||||||
|
|
||||||
class Person: CoreStoreObject {
|
class Person: CoreStoreObject {
|
||||||
let name = Value.Required<String>("name")
|
let name = Value.Required<String>("name", initial: "")
|
||||||
}
|
}
|
||||||
|
|
||||||
CoreStore.defaultStack = DataStack(
|
CoreStore.defaultStack = DataStack(
|
||||||
@@ -208,7 +208,7 @@ public final class CoreStoreSchema: DynamicSchema {
|
|||||||
}
|
}
|
||||||
let rawModel = NSManagedObjectModel()
|
let rawModel = NSManagedObjectModel()
|
||||||
var entityDescriptionsByEntity: [DynamicEntity: NSEntityDescription] = [:]
|
var entityDescriptionsByEntity: [DynamicEntity: NSEntityDescription] = [:]
|
||||||
var allCustomGettersSetters: [DynamicEntity: [KeyPath: CoreStoreManagedObject.CustomGetterSetter]] = [:]
|
var allCustomGettersSetters: [DynamicEntity: [RawKeyPath: CoreStoreManagedObject.CustomGetterSetter]] = [:]
|
||||||
for entity in self.allEntities {
|
for entity in self.allEntities {
|
||||||
|
|
||||||
let (entityDescription, customGetterSetterByKeyPaths) = self.entityDescription(
|
let (entityDescription, customGetterSetterByKeyPaths) = self.entityDescription(
|
||||||
@@ -253,10 +253,10 @@ public final class CoreStoreSchema: DynamicSchema {
|
|||||||
private let allEntities: Set<DynamicEntity>
|
private let allEntities: Set<DynamicEntity>
|
||||||
|
|
||||||
private var entityDescriptionsByEntity: [DynamicEntity: NSEntityDescription] = [:]
|
private var entityDescriptionsByEntity: [DynamicEntity: NSEntityDescription] = [:]
|
||||||
private var customGettersSettersByEntity: [DynamicEntity: [KeyPath: CoreStoreManagedObject.CustomGetterSetter]] = [:]
|
private var customGettersSettersByEntity: [DynamicEntity: [RawKeyPath: CoreStoreManagedObject.CustomGetterSetter]] = [:]
|
||||||
private weak var cachedRawModel: NSManagedObjectModel?
|
private weak var cachedRawModel: NSManagedObjectModel?
|
||||||
|
|
||||||
private func entityDescription(for entity: DynamicEntity, initializer: (DynamicEntity, ModelVersion) -> (entity: NSEntityDescription, customGetterSetterByKeyPaths: [KeyPath: CoreStoreManagedObject.CustomGetterSetter])) -> (entity: NSEntityDescription, customGetterSetterByKeyPaths: [KeyPath: CoreStoreManagedObject.CustomGetterSetter]) {
|
private func entityDescription(for entity: DynamicEntity, initializer: (DynamicEntity, ModelVersion) -> (entity: NSEntityDescription, customGetterSetterByKeyPaths: [RawKeyPath: CoreStoreManagedObject.CustomGetterSetter])) -> (entity: NSEntityDescription, customGetterSetterByKeyPaths: [RawKeyPath: CoreStoreManagedObject.CustomGetterSetter]) {
|
||||||
|
|
||||||
if let cachedEntityDescription = self.entityDescriptionsByEntity[entity] {
|
if let cachedEntityDescription = self.entityDescriptionsByEntity[entity] {
|
||||||
|
|
||||||
@@ -269,7 +269,7 @@ public final class CoreStoreSchema: DynamicSchema {
|
|||||||
return (entityDescription, customGetterSetterByKeyPaths)
|
return (entityDescription, customGetterSetterByKeyPaths)
|
||||||
}
|
}
|
||||||
|
|
||||||
private static func firstPassCreateEntityDescription(from entity: DynamicEntity, in modelVersion: ModelVersion) -> (entity: NSEntityDescription, customGetterSetterByKeyPaths: [KeyPath: CoreStoreManagedObject.CustomGetterSetter]) {
|
private static func firstPassCreateEntityDescription(from entity: DynamicEntity, in modelVersion: ModelVersion) -> (entity: NSEntityDescription, customGetterSetterByKeyPaths: [RawKeyPath: CoreStoreManagedObject.CustomGetterSetter]) {
|
||||||
|
|
||||||
let entityDescription = NSEntityDescription()
|
let entityDescription = NSEntityDescription()
|
||||||
entityDescription.coreStoreEntity = entity
|
entityDescription.coreStoreEntity = entity
|
||||||
@@ -278,8 +278,8 @@ public final class CoreStoreSchema: DynamicSchema {
|
|||||||
entityDescription.versionHashModifier = entity.versionHashModifier
|
entityDescription.versionHashModifier = entity.versionHashModifier
|
||||||
entityDescription.managedObjectClassName = CoreStoreManagedObject.cs_subclassName(for: entity, in: modelVersion)
|
entityDescription.managedObjectClassName = CoreStoreManagedObject.cs_subclassName(for: entity, in: modelVersion)
|
||||||
|
|
||||||
var keyPathsByAffectedKeyPaths: [KeyPath: Set<KeyPath>] = [:]
|
var keyPathsByAffectedKeyPaths: [RawKeyPath: Set<RawKeyPath>] = [:]
|
||||||
var customGetterSetterByKeyPaths: [KeyPath: CoreStoreManagedObject.CustomGetterSetter] = [:]
|
var customGetterSetterByKeyPaths: [RawKeyPath: CoreStoreManagedObject.CustomGetterSetter] = [:]
|
||||||
func createProperties(for type: CoreStoreObject.Type) -> [NSPropertyDescription] {
|
func createProperties(for type: CoreStoreObject.Type) -> [NSPropertyDescription] {
|
||||||
|
|
||||||
var propertyDescriptions: [NSPropertyDescription] = []
|
var propertyDescriptions: [NSPropertyDescription] = []
|
||||||
@@ -443,9 +443,9 @@ public final class CoreStoreSchema: DynamicSchema {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static func fourthPassSynthesizeManagedObjectClasses(for entityDescriptionsByEntity: [DynamicEntity: NSEntityDescription], allCustomGettersSetters: [DynamicEntity: [KeyPath: CoreStoreManagedObject.CustomGetterSetter]]) {
|
private static func fourthPassSynthesizeManagedObjectClasses(for entityDescriptionsByEntity: [DynamicEntity: NSEntityDescription], allCustomGettersSetters: [DynamicEntity: [RawKeyPath: CoreStoreManagedObject.CustomGetterSetter]]) {
|
||||||
|
|
||||||
func createManagedObjectSubclass(for entityDescription: NSEntityDescription, customGetterSetterByKeyPaths: [KeyPath: CoreStoreManagedObject.CustomGetterSetter]?) {
|
func createManagedObjectSubclass(for entityDescription: NSEntityDescription, customGetterSetterByKeyPaths: [RawKeyPath: CoreStoreManagedObject.CustomGetterSetter]?) {
|
||||||
|
|
||||||
let superEntity = entityDescription.superentity
|
let superEntity = entityDescription.superentity
|
||||||
let className = entityDescription.managedObjectClassName!
|
let className = entityDescription.managedObjectClassName!
|
||||||
|
|||||||
@@ -210,7 +210,7 @@ public class CustomSchemaMappingProvider: Hashable, SchemaMappingProvider {
|
|||||||
/**
|
/**
|
||||||
Accesses the property value via its keyPath.
|
Accesses the property value via its keyPath.
|
||||||
*/
|
*/
|
||||||
public subscript(attribute: KeyPath) -> Any? {
|
public subscript(attribute: RawKeyPath) -> Any? {
|
||||||
|
|
||||||
return self.rawObject.cs_accessValueForKVCKey(attribute)
|
return self.rawObject.cs_accessValueForKVCKey(attribute)
|
||||||
}
|
}
|
||||||
@@ -267,7 +267,7 @@ public class CustomSchemaMappingProvider: Hashable, SchemaMappingProvider {
|
|||||||
/**
|
/**
|
||||||
Accesses or mutates the property value via its keyPath.
|
Accesses or mutates the property value via its keyPath.
|
||||||
*/
|
*/
|
||||||
public subscript(attribute: KeyPath) -> Any? {
|
public subscript(attribute: RawKeyPath) -> Any? {
|
||||||
|
|
||||||
get { return self.rawObject.cs_accessValueForKVCKey(attribute) }
|
get { return self.rawObject.cs_accessValueForKVCKey(attribute) }
|
||||||
set { self.rawObject.cs_setValue(newValue, forKVCKey: attribute) }
|
set { self.rawObject.cs_setValue(newValue, forKVCKey: attribute) }
|
||||||
@@ -304,7 +304,7 @@ public class CustomSchemaMappingProvider: Hashable, SchemaMappingProvider {
|
|||||||
|
|
||||||
// MARK: Internal
|
// MARK: Internal
|
||||||
|
|
||||||
internal init(_ rawObject: NSManagedObject, _ sourceAttributesByDestinationKey: [KeyPath: NSAttributeDescription]) {
|
internal init(_ rawObject: NSManagedObject, _ sourceAttributesByDestinationKey: [RawKeyPath: NSAttributeDescription]) {
|
||||||
|
|
||||||
self.rawObject = rawObject
|
self.rawObject = rawObject
|
||||||
self.sourceAttributesByDestinationKey = sourceAttributesByDestinationKey
|
self.sourceAttributesByDestinationKey = sourceAttributesByDestinationKey
|
||||||
@@ -314,7 +314,7 @@ public class CustomSchemaMappingProvider: Hashable, SchemaMappingProvider {
|
|||||||
// MARK: FilePrivate
|
// MARK: FilePrivate
|
||||||
|
|
||||||
fileprivate let rawObject: NSManagedObject
|
fileprivate let rawObject: NSManagedObject
|
||||||
fileprivate let sourceAttributesByDestinationKey: [KeyPath: NSAttributeDescription]
|
fileprivate let sourceAttributesByDestinationKey: [RawKeyPath: NSAttributeDescription]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -477,7 +477,7 @@ public class CustomSchemaMappingProvider: Hashable, SchemaMappingProvider {
|
|||||||
let transformedRenamingIdentifiers = Set(destinationAttributes.keys)
|
let transformedRenamingIdentifiers = Set(destinationAttributes.keys)
|
||||||
.intersection(sourceAttributes.keys)
|
.intersection(sourceAttributes.keys)
|
||||||
|
|
||||||
var sourceAttributesByDestinationKey: [KeyPath: NSAttributeDescription] = [:]
|
var sourceAttributesByDestinationKey: [RawKeyPath: NSAttributeDescription] = [:]
|
||||||
for renamingIdentifier in transformedRenamingIdentifiers {
|
for renamingIdentifier in transformedRenamingIdentifiers {
|
||||||
|
|
||||||
let sourceAttribute = sourceAttributes[renamingIdentifier]!.attribute
|
let sourceAttribute = sourceAttributes[renamingIdentifier]!.attribute
|
||||||
@@ -535,7 +535,7 @@ public class CustomSchemaMappingProvider: Hashable, SchemaMappingProvider {
|
|||||||
|
|
||||||
let userInfo = mapping.userInfo!
|
let userInfo = mapping.userInfo!
|
||||||
let transformer = userInfo[CustomEntityMigrationPolicy.UserInfoKey.transformer]! as! CustomMapping.Transformer
|
let transformer = userInfo[CustomEntityMigrationPolicy.UserInfoKey.transformer]! as! CustomMapping.Transformer
|
||||||
let sourceAttributesByDestinationKey = userInfo[CustomEntityMigrationPolicy.UserInfoKey.sourceAttributesByDestinationKey] as! [KeyPath: NSAttributeDescription]
|
let sourceAttributesByDestinationKey = userInfo[CustomEntityMigrationPolicy.UserInfoKey.sourceAttributesByDestinationKey] as! [RawKeyPath: NSAttributeDescription]
|
||||||
|
|
||||||
var destinationObject: UnsafeDestinationObject?
|
var destinationObject: UnsafeDestinationObject?
|
||||||
try transformer(
|
try transformer(
|
||||||
@@ -585,8 +585,8 @@ public class CustomSchemaMappingProvider: Hashable, SchemaMappingProvider {
|
|||||||
var insertMappings: Set<CustomMapping> = []
|
var insertMappings: Set<CustomMapping> = []
|
||||||
var copyMappings: Set<CustomMapping> = []
|
var copyMappings: Set<CustomMapping> = []
|
||||||
var transformMappings: Set<CustomMapping> = []
|
var transformMappings: Set<CustomMapping> = []
|
||||||
var allMappedSourceKeys: [KeyPath: KeyPath] = [:]
|
var allMappedSourceKeys: [RawKeyPath: RawKeyPath] = [:]
|
||||||
var allMappedDestinationKeys: [KeyPath: KeyPath] = [:]
|
var allMappedDestinationKeys: [RawKeyPath: RawKeyPath] = [:]
|
||||||
|
|
||||||
let sourceRenamingIdentifiers = sourceModel.cs_resolvedRenamingIdentities()
|
let sourceRenamingIdentifiers = sourceModel.cs_resolvedRenamingIdentities()
|
||||||
let sourceEntityNames = sourceModel.entitiesByName
|
let sourceEntityNames = sourceModel.entitiesByName
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ public extension DataStack {
|
|||||||
- parameter storage: the storage
|
- parameter storage: the storage
|
||||||
- parameter completion: the closure to be executed on the main queue when the process completes, either due to success or failure. The closure's `SetupResult` argument indicates the result. Note that the `StorageInterface` associated to the `SetupResult.success` may not always be the same instance as the parameter argument if a previous `StorageInterface` was already added at the same URL and with the same configuration.
|
- parameter completion: the closure to be executed on the main queue when the process completes, either due to success or failure. The closure's `SetupResult` argument indicates the result. Note that the `StorageInterface` associated to the `SetupResult.success` may not always be the same instance as the parameter argument if a previous `StorageInterface` was already added at the same URL and with the same configuration.
|
||||||
*/
|
*/
|
||||||
public func addStorage<T: StorageInterface>(_ storage: T, completion: @escaping (SetupResult<T>) -> Void) {
|
public func addStorage<T>(_ storage: T, completion: @escaping (SetupResult<T>) -> Void) {
|
||||||
|
|
||||||
self.coordinator.performAsynchronously {
|
self.coordinator.performAsynchronously {
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ public extension DataStack {
|
|||||||
- parameter object: the `DynamicObject` to observe changes from
|
- parameter object: the `DynamicObject` to observe changes from
|
||||||
- returns: a `ObjectMonitor` that monitors changes to `object`
|
- returns: a `ObjectMonitor` that monitors changes to `object`
|
||||||
*/
|
*/
|
||||||
public func monitorObject<T: DynamicObject>(_ object: T) -> ObjectMonitor<T> {
|
public func monitorObject<T>(_ object: T) -> ObjectMonitor<T> {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
Thread.isMainThread,
|
Thread.isMainThread,
|
||||||
@@ -54,7 +54,7 @@ public extension DataStack {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: a `ListMonitor` instance that monitors changes to the list
|
- returns: a `ListMonitor` instance that monitors changes to the list
|
||||||
*/
|
*/
|
||||||
public func monitorList<T: DynamicObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> ListMonitor<T> {
|
public func monitorList<T>(_ from: From<T>, _ fetchClauses: FetchClause...) -> ListMonitor<T> {
|
||||||
|
|
||||||
return self.monitorList(from, fetchClauses)
|
return self.monitorList(from, fetchClauses)
|
||||||
}
|
}
|
||||||
@@ -66,7 +66,7 @@ public extension DataStack {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: a `ListMonitor` instance that monitors changes to the list
|
- returns: a `ListMonitor` instance that monitors changes to the list
|
||||||
*/
|
*/
|
||||||
public func monitorList<T: DynamicObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> ListMonitor<T> {
|
public func monitorList<T>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> ListMonitor<T> {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
Thread.isMainThread,
|
Thread.isMainThread,
|
||||||
@@ -95,7 +95,7 @@ public extension DataStack {
|
|||||||
- parameter from: a `From` clause indicating the entity type
|
- parameter from: a `From` clause indicating the entity type
|
||||||
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
*/
|
*/
|
||||||
public func monitorList<T: DynamicObject>(createAsynchronously: @escaping (ListMonitor<T>) -> Void, _ from: From<T>, _ fetchClauses: FetchClause...) {
|
public func monitorList<T>(createAsynchronously: @escaping (ListMonitor<T>) -> Void, _ from: From<T>, _ fetchClauses: FetchClause...) {
|
||||||
|
|
||||||
self.monitorList(createAsynchronously: createAsynchronously, from, fetchClauses)
|
self.monitorList(createAsynchronously: createAsynchronously, from, fetchClauses)
|
||||||
}
|
}
|
||||||
@@ -107,7 +107,7 @@ public extension DataStack {
|
|||||||
- parameter from: a `From` clause indicating the entity type
|
- parameter from: a `From` clause indicating the entity type
|
||||||
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
*/
|
*/
|
||||||
public func monitorList<T: DynamicObject>(createAsynchronously: @escaping (ListMonitor<T>) -> Void, _ from: From<T>, _ fetchClauses: [FetchClause]) {
|
public func monitorList<T>(createAsynchronously: @escaping (ListMonitor<T>) -> Void, _ from: From<T>, _ fetchClauses: [FetchClause]) {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
Thread.isMainThread,
|
Thread.isMainThread,
|
||||||
@@ -138,7 +138,7 @@ public extension DataStack {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: a `ListMonitor` instance that monitors changes to the list
|
- returns: a `ListMonitor` instance that monitors changes to the list
|
||||||
*/
|
*/
|
||||||
public func monitorSectionedList<T: DynamicObject>(_ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) -> ListMonitor<T> {
|
public func monitorSectionedList<T>(_ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) -> ListMonitor<T> {
|
||||||
|
|
||||||
return self.monitorSectionedList(from, sectionBy, fetchClauses)
|
return self.monitorSectionedList(from, sectionBy, fetchClauses)
|
||||||
}
|
}
|
||||||
@@ -151,7 +151,7 @@ public extension DataStack {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: a `ListMonitor` instance that monitors changes to the list
|
- returns: a `ListMonitor` instance that monitors changes to the list
|
||||||
*/
|
*/
|
||||||
public func monitorSectionedList<T: DynamicObject>(_ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) -> ListMonitor<T> {
|
public func monitorSectionedList<T>(_ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) -> ListMonitor<T> {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
Thread.isMainThread,
|
Thread.isMainThread,
|
||||||
@@ -182,7 +182,7 @@ public extension DataStack {
|
|||||||
- parameter sectionBy: a `SectionBy` clause indicating the keyPath for the attribute to use when sorting the list into sections.
|
- parameter sectionBy: a `SectionBy` clause indicating the keyPath for the attribute to use when sorting the list into sections.
|
||||||
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
*/
|
*/
|
||||||
public func monitorSectionedList<T: DynamicObject>(createAsynchronously: @escaping (ListMonitor<T>) -> Void, _ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) {
|
public func monitorSectionedList<T>(createAsynchronously: @escaping (ListMonitor<T>) -> Void, _ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) {
|
||||||
|
|
||||||
self.monitorSectionedList(createAsynchronously: createAsynchronously, from, sectionBy, fetchClauses)
|
self.monitorSectionedList(createAsynchronously: createAsynchronously, from, sectionBy, fetchClauses)
|
||||||
}
|
}
|
||||||
@@ -195,7 +195,7 @@ public extension DataStack {
|
|||||||
- parameter sectionBy: a `SectionBy` clause indicating the keyPath for the attribute to use when sorting the list into sections.
|
- parameter sectionBy: a `SectionBy` clause indicating the keyPath for the attribute to use when sorting the list into sections.
|
||||||
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
*/
|
*/
|
||||||
public func monitorSectionedList<T: DynamicObject>(createAsynchronously: @escaping (ListMonitor<T>) -> Void, _ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) {
|
public func monitorSectionedList<T>(createAsynchronously: @escaping (ListMonitor<T>) -> Void, _ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
Thread.isMainThread,
|
Thread.isMainThread,
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ extension DataStack: FetchableSource, QueryableSource {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: the first `DynamicObject` instance that satisfies the specified `FetchClause`s
|
- returns: the first `DynamicObject` instance that satisfies the specified `FetchClause`s
|
||||||
*/
|
*/
|
||||||
public func fetchOne<T: DynamicObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> T? {
|
public func fetchOne<T>(_ from: From<T>, _ fetchClauses: FetchClause...) -> T? {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
Thread.isMainThread,
|
Thread.isMainThread,
|
||||||
@@ -100,7 +100,7 @@ extension DataStack: FetchableSource, QueryableSource {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: the first `DynamicObject` instance that satisfies the specified `FetchClause`s
|
- returns: the first `DynamicObject` instance that satisfies the specified `FetchClause`s
|
||||||
*/
|
*/
|
||||||
public func fetchOne<T: DynamicObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> T? {
|
public func fetchOne<T>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> T? {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
Thread.isMainThread,
|
Thread.isMainThread,
|
||||||
@@ -116,7 +116,7 @@ extension DataStack: FetchableSource, QueryableSource {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: all `DynamicObject` instances that satisfy the specified `FetchClause`s
|
- returns: all `DynamicObject` instances that satisfy the specified `FetchClause`s
|
||||||
*/
|
*/
|
||||||
public func fetchAll<T: DynamicObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> [T]? {
|
public func fetchAll<T>(_ from: From<T>, _ fetchClauses: FetchClause...) -> [T]? {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
Thread.isMainThread,
|
Thread.isMainThread,
|
||||||
@@ -132,7 +132,7 @@ extension DataStack: FetchableSource, QueryableSource {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: all `DynamicObject` instances that satisfy the specified `FetchClause`s
|
- returns: all `DynamicObject` instances that satisfy the specified `FetchClause`s
|
||||||
*/
|
*/
|
||||||
public func fetchAll<T: DynamicObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> [T]? {
|
public func fetchAll<T>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> [T]? {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
Thread.isMainThread,
|
Thread.isMainThread,
|
||||||
@@ -148,7 +148,7 @@ extension DataStack: FetchableSource, QueryableSource {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: the number `DynamicObject`s that satisfy the specified `FetchClause`s
|
- returns: the number `DynamicObject`s that satisfy the specified `FetchClause`s
|
||||||
*/
|
*/
|
||||||
public func fetchCount<T: DynamicObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> Int? {
|
public func fetchCount<T>(_ from: From<T>, _ fetchClauses: FetchClause...) -> Int? {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
Thread.isMainThread,
|
Thread.isMainThread,
|
||||||
@@ -164,7 +164,7 @@ extension DataStack: FetchableSource, QueryableSource {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: the number `DynamicObject`s that satisfy the specified `FetchClause`s
|
- returns: the number `DynamicObject`s that satisfy the specified `FetchClause`s
|
||||||
*/
|
*/
|
||||||
public func fetchCount<T: DynamicObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> Int? {
|
public func fetchCount<T>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> Int? {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
Thread.isMainThread,
|
Thread.isMainThread,
|
||||||
@@ -180,7 +180,7 @@ extension DataStack: FetchableSource, QueryableSource {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s
|
- returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s
|
||||||
*/
|
*/
|
||||||
public func fetchObjectID<T: DynamicObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> NSManagedObjectID? {
|
public func fetchObjectID<T>(_ from: From<T>, _ fetchClauses: FetchClause...) -> NSManagedObjectID? {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
Thread.isMainThread,
|
Thread.isMainThread,
|
||||||
@@ -196,7 +196,7 @@ extension DataStack: FetchableSource, QueryableSource {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s
|
- returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s
|
||||||
*/
|
*/
|
||||||
public func fetchObjectID<T: DynamicObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> NSManagedObjectID? {
|
public func fetchObjectID<T>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> NSManagedObjectID? {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
Thread.isMainThread,
|
Thread.isMainThread,
|
||||||
@@ -212,7 +212,7 @@ extension DataStack: FetchableSource, QueryableSource {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s
|
- returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s
|
||||||
*/
|
*/
|
||||||
public func fetchObjectIDs<T: DynamicObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> [NSManagedObjectID]? {
|
public func fetchObjectIDs<T>(_ from: From<T>, _ fetchClauses: FetchClause...) -> [NSManagedObjectID]? {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
Thread.isMainThread,
|
Thread.isMainThread,
|
||||||
@@ -228,7 +228,7 @@ extension DataStack: FetchableSource, QueryableSource {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s
|
- returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s
|
||||||
*/
|
*/
|
||||||
public func fetchObjectIDs<T: DynamicObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> [NSManagedObjectID]? {
|
public func fetchObjectIDs<T>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> [NSManagedObjectID]? {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
Thread.isMainThread,
|
Thread.isMainThread,
|
||||||
@@ -250,7 +250,7 @@ extension DataStack: FetchableSource, QueryableSource {
|
|||||||
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
||||||
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
||||||
*/
|
*/
|
||||||
public func queryValue<T: DynamicObject, U: QueryableAttributeType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: QueryClause...) -> U? {
|
public func queryValue<T, U: QueryableAttributeType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: QueryClause...) -> U? {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
Thread.isMainThread,
|
Thread.isMainThread,
|
||||||
@@ -269,7 +269,7 @@ extension DataStack: FetchableSource, QueryableSource {
|
|||||||
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
||||||
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
||||||
*/
|
*/
|
||||||
public func queryValue<T: DynamicObject, U: QueryableAttributeType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: [QueryClause]) -> U? {
|
public func queryValue<T, U: QueryableAttributeType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: [QueryClause]) -> U? {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
Thread.isMainThread,
|
Thread.isMainThread,
|
||||||
@@ -288,7 +288,7 @@ extension DataStack: FetchableSource, QueryableSource {
|
|||||||
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
||||||
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
||||||
*/
|
*/
|
||||||
public func queryAttributes<T: DynamicObject>(_ from: From<T>, _ selectClause: Select<NSDictionary>, _ queryClauses: QueryClause...) -> [[String: Any]]? {
|
public func queryAttributes<T>(_ from: From<T>, _ selectClause: Select<NSDictionary>, _ queryClauses: QueryClause...) -> [[String: Any]]? {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
Thread.isMainThread,
|
Thread.isMainThread,
|
||||||
@@ -307,7 +307,7 @@ extension DataStack: FetchableSource, QueryableSource {
|
|||||||
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
||||||
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
||||||
*/
|
*/
|
||||||
public func queryAttributes<T: DynamicObject>(_ from: From<T>, _ selectClause: Select<NSDictionary>, _ queryClauses: [QueryClause]) -> [[String: Any]]? {
|
public func queryAttributes<T>(_ from: From<T>, _ selectClause: Select<NSDictionary>, _ queryClauses: [QueryClause]) -> [[String: Any]]? {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
Thread.isMainThread,
|
Thread.isMainThread,
|
||||||
|
|||||||
@@ -61,10 +61,6 @@ public extension DataStack {
|
|||||||
)
|
)
|
||||||
transaction.transactionQueue.cs_async {
|
transaction.transactionQueue.cs_async {
|
||||||
|
|
||||||
defer {
|
|
||||||
|
|
||||||
withExtendedLifetime((self, transaction), {})
|
|
||||||
}
|
|
||||||
let userInfo: T
|
let userInfo: T
|
||||||
do {
|
do {
|
||||||
|
|
||||||
@@ -82,6 +78,10 @@ public extension DataStack {
|
|||||||
}
|
}
|
||||||
transaction.autoCommit { (_, error) in
|
transaction.autoCommit { (_, error) in
|
||||||
|
|
||||||
|
defer {
|
||||||
|
|
||||||
|
withExtendedLifetime((self, transaction), {})
|
||||||
|
}
|
||||||
if let error = error {
|
if let error = error {
|
||||||
|
|
||||||
failure(error)
|
failure(error)
|
||||||
@@ -211,9 +211,9 @@ public extension DataStack {
|
|||||||
}
|
}
|
||||||
switch transaction.result {
|
switch transaction.result {
|
||||||
|
|
||||||
case nil: return nil
|
case .none: return nil
|
||||||
case (let hasChanges, nil)?: return SaveResult(hasChanges: hasChanges)
|
case .some(let hasChanges, nil): return SaveResult(hasChanges: hasChanges)
|
||||||
case (_, let error?)?: return SaveResult(error)
|
case .some(_, let error?): return SaveResult(error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -105,9 +105,6 @@ public final class DataStack: Equatable {
|
|||||||
*/
|
*/
|
||||||
public required init(schemaHistory: SchemaHistory) {
|
public required init(schemaHistory: SchemaHistory) {
|
||||||
|
|
||||||
// TODO: test before release (rolled back)
|
|
||||||
// _ = DataStack.isGloballyInitialized
|
|
||||||
|
|
||||||
self.coordinator = NSPersistentStoreCoordinator(managedObjectModel: schemaHistory.rawModel)
|
self.coordinator = NSPersistentStoreCoordinator(managedObjectModel: schemaHistory.rawModel)
|
||||||
self.rootSavingContext = NSManagedObjectContext.rootSavingContextForCoordinator(self.coordinator)
|
self.rootSavingContext = NSManagedObjectContext.rootSavingContextForCoordinator(self.coordinator)
|
||||||
self.mainContext = NSManagedObjectContext.mainContextForRootContext(self.rootSavingContext)
|
self.mainContext = NSManagedObjectContext.mainContextForRootContext(self.rootSavingContext)
|
||||||
@@ -585,13 +582,6 @@ public final class DataStack: Equatable {
|
|||||||
|
|
||||||
// MARK: Private
|
// MARK: Private
|
||||||
|
|
||||||
// TODO: test before release (rolled back)
|
|
||||||
// private static let isGloballyInitialized: Bool = {
|
|
||||||
//
|
|
||||||
// NSManagedObject.cs_swizzleMethodsForLogging()
|
|
||||||
// return true
|
|
||||||
// }()
|
|
||||||
|
|
||||||
private var persistentStoresByFinalConfiguration = [String: NSPersistentStore]()
|
private var persistentStoresByFinalConfiguration = [String: NSPersistentStore]()
|
||||||
private var finalConfigurationsByEntityIdentifier = [EntityIdentifier: Set<String>]()
|
private var finalConfigurationsByEntityIdentifier = [EntityIdentifier: Set<String>]()
|
||||||
|
|
||||||
|
|||||||
@@ -33,12 +33,6 @@ import Foundation
|
|||||||
*/
|
*/
|
||||||
public final class DefaultLogger: CoreStoreLogger {
|
public final class DefaultLogger: CoreStoreLogger {
|
||||||
|
|
||||||
/**
|
|
||||||
When `true`, all `NSManagedObject` attribute and relationship access will raise an assertion when executed on the wrong transaction/datastack queue. Defaults to `false`.
|
|
||||||
*/
|
|
||||||
// TODO: test before release (rolled back)
|
|
||||||
// public var enableObjectConcurrencyDebugging: Bool = false
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Creates a `DefaultLogger`.
|
Creates a `DefaultLogger`.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -78,12 +78,7 @@ extension NSManagedObject: DynamicObject {
|
|||||||
|
|
||||||
public class func cs_fromRaw(object: NSManagedObject) -> Self {
|
public class func cs_fromRaw(object: NSManagedObject) -> Self {
|
||||||
|
|
||||||
@inline(__always)
|
return unsafeDowncast(object, to: self)
|
||||||
func forceCast<T: NSManagedObject>(_ value: Any) -> T {
|
|
||||||
|
|
||||||
return value as! T
|
|
||||||
}
|
|
||||||
return forceCast(object)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func cs_matches(object: NSManagedObject) -> Bool {
|
public static func cs_matches(object: NSManagedObject) -> Bool {
|
||||||
@@ -124,12 +119,7 @@ extension CoreStoreObject {
|
|||||||
|
|
||||||
if let coreStoreObject = object.coreStoreObject {
|
if let coreStoreObject = object.coreStoreObject {
|
||||||
|
|
||||||
@inline(__always)
|
return unsafeDowncast(coreStoreObject, to: self)
|
||||||
func forceCast<T: CoreStoreObject>(_ value: CoreStoreObject) -> T {
|
|
||||||
|
|
||||||
return value as! T
|
|
||||||
}
|
|
||||||
return forceCast(coreStoreObject)
|
|
||||||
}
|
}
|
||||||
@inline(__always)
|
@inline(__always)
|
||||||
func forceTypeCast<T: CoreStoreObject>(_ type: DynamicObject.Type, to: T.Type) -> T.Type {
|
func forceTypeCast<T: CoreStoreObject>(_ type: DynamicObject.Type, to: T.Type) -> T.Type {
|
||||||
|
|||||||
@@ -96,19 +96,19 @@ public extension DynamicSchema {
|
|||||||
|
|
||||||
case .integer16AttributeType:
|
case .integer16AttributeType:
|
||||||
valueType = Int16.self
|
valueType = Int16.self
|
||||||
if let defaultValue = (attribute.defaultValue as! Int16.ImportableNativeType?).flatMap(Int16.cs_fromImportableNativeType) {
|
if let defaultValue = (attribute.defaultValue as! Int16.QueryableNativeType?).flatMap(Int16.cs_fromQueryableNativeType) {
|
||||||
|
|
||||||
defaultString = ", initial: \(defaultValue)"
|
defaultString = ", initial: \(defaultValue)"
|
||||||
}
|
}
|
||||||
case .integer32AttributeType:
|
case .integer32AttributeType:
|
||||||
valueType = Int32.self
|
valueType = Int32.self
|
||||||
if let defaultValue = (attribute.defaultValue as! Int32.ImportableNativeType?).flatMap(Int32.cs_fromImportableNativeType) {
|
if let defaultValue = (attribute.defaultValue as! Int32.QueryableNativeType?).flatMap(Int32.cs_fromQueryableNativeType) {
|
||||||
|
|
||||||
defaultString = ", initial: \(defaultValue)"
|
defaultString = ", initial: \(defaultValue)"
|
||||||
}
|
}
|
||||||
case .integer64AttributeType:
|
case .integer64AttributeType:
|
||||||
valueType = Int64.self
|
valueType = Int64.self
|
||||||
if let defaultValue = (attribute.defaultValue as! Int64.ImportableNativeType?).flatMap(Int64.cs_fromImportableNativeType) {
|
if let defaultValue = (attribute.defaultValue as! Int64.QueryableNativeType?).flatMap(Int64.cs_fromQueryableNativeType) {
|
||||||
|
|
||||||
defaultString = ", initial: \(defaultValue)"
|
defaultString = ", initial: \(defaultValue)"
|
||||||
}
|
}
|
||||||
@@ -120,38 +120,38 @@ public extension DynamicSchema {
|
|||||||
}
|
}
|
||||||
case .doubleAttributeType:
|
case .doubleAttributeType:
|
||||||
valueType = Double.self
|
valueType = Double.self
|
||||||
if let defaultValue = (attribute.defaultValue as! Double.ImportableNativeType?).flatMap(Double.cs_fromImportableNativeType) {
|
if let defaultValue = (attribute.defaultValue as! Double.QueryableNativeType?).flatMap(Double.cs_fromQueryableNativeType) {
|
||||||
|
|
||||||
defaultString = ", initial: \(defaultValue)"
|
defaultString = ", initial: \(defaultValue)"
|
||||||
}
|
}
|
||||||
case .floatAttributeType:
|
case .floatAttributeType:
|
||||||
valueType = Float.self
|
valueType = Float.self
|
||||||
if let defaultValue = (attribute.defaultValue as! Float.ImportableNativeType?).flatMap(Float.cs_fromImportableNativeType) {
|
if let defaultValue = (attribute.defaultValue as! Float.QueryableNativeType?).flatMap(Float.cs_fromQueryableNativeType) {
|
||||||
|
|
||||||
defaultString = ", initial: \(defaultValue)"
|
defaultString = ", initial: \(defaultValue)"
|
||||||
}
|
}
|
||||||
case .stringAttributeType:
|
case .stringAttributeType:
|
||||||
valueType = String.self
|
valueType = String.self
|
||||||
if let defaultValue = (attribute.defaultValue as! String.ImportableNativeType?).flatMap(String.cs_fromImportableNativeType) {
|
if let defaultValue = (attribute.defaultValue as! String.QueryableNativeType?).flatMap(String.cs_fromQueryableNativeType) {
|
||||||
|
|
||||||
// TODO: escape strings
|
// TODO: escape strings
|
||||||
defaultString = ", initial: \"\(defaultValue)\""
|
defaultString = ", initial: \"\(defaultValue)\""
|
||||||
}
|
}
|
||||||
case .booleanAttributeType:
|
case .booleanAttributeType:
|
||||||
valueType = Bool.self
|
valueType = Bool.self
|
||||||
if let defaultValue = (attribute.defaultValue as! Bool.ImportableNativeType?).flatMap(Bool.cs_fromImportableNativeType) {
|
if let defaultValue = (attribute.defaultValue as! Bool.QueryableNativeType?).flatMap(Bool.cs_fromQueryableNativeType) {
|
||||||
|
|
||||||
defaultString = ", initial: \(defaultValue ? "true" : "false")"
|
defaultString = ", initial: \(defaultValue ? "true" : "false")"
|
||||||
}
|
}
|
||||||
case .dateAttributeType:
|
case .dateAttributeType:
|
||||||
valueType = Date.self
|
valueType = Date.self
|
||||||
if let defaultValue = (attribute.defaultValue as! Date.ImportableNativeType?).flatMap(Date.cs_fromImportableNativeType) {
|
if let defaultValue = (attribute.defaultValue as! Date.QueryableNativeType?).flatMap(Date.cs_fromQueryableNativeType) {
|
||||||
|
|
||||||
defaultString = ", initial: Date(timeIntervalSinceReferenceDate: \(defaultValue.timeIntervalSinceReferenceDate))"
|
defaultString = ", initial: Date(timeIntervalSinceReferenceDate: \(defaultValue.timeIntervalSinceReferenceDate))"
|
||||||
}
|
}
|
||||||
case .binaryDataAttributeType:
|
case .binaryDataAttributeType:
|
||||||
valueType = Data.self
|
valueType = Data.self
|
||||||
if let defaultValue = (attribute.defaultValue as! Data.ImportableNativeType?).flatMap(Data.cs_fromImportableNativeType) {
|
if let defaultValue = (attribute.defaultValue as! Data.QueryableNativeType?).flatMap(Data.cs_fromQueryableNativeType) {
|
||||||
|
|
||||||
let count = defaultValue.count
|
let count = defaultValue.count
|
||||||
let bytes = defaultValue.withUnsafeBytes { (pointer: UnsafePointer<UInt8>) in
|
let bytes = defaultValue.withUnsafeBytes { (pointer: UnsafePointer<UInt8>) in
|
||||||
|
|||||||
@@ -34,13 +34,13 @@ import ObjectiveC
|
|||||||
The `Entity<O>` contains `NSEntityDescription` metadata for `CoreStoreObject` subclasses. Pass the `Entity` instances to `CoreStoreSchema` initializer.
|
The `Entity<O>` contains `NSEntityDescription` metadata for `CoreStoreObject` subclasses. Pass the `Entity` instances to `CoreStoreSchema` initializer.
|
||||||
```
|
```
|
||||||
class Animal: CoreStoreObject {
|
class Animal: CoreStoreObject {
|
||||||
let species = Value.Required<String>("species")
|
let species = Value.Required<String>("species", initial: "")
|
||||||
let nickname = Value.Optional<String>("nickname")
|
let nickname = Value.Optional<String>("nickname")
|
||||||
let master = Relationship.ToOne<Person>("master")
|
let master = Relationship.ToOne<Person>("master")
|
||||||
}
|
}
|
||||||
|
|
||||||
class Person: CoreStoreObject {
|
class Person: CoreStoreObject {
|
||||||
let name = Value.Required<String>("name")
|
let name = Value.Required<String>("name", initial: "")
|
||||||
let pet = Relationship.ToOne<Animal>("pet", inverse: { $0.master })
|
let pet = Relationship.ToOne<Animal>("pet", inverse: { $0.master })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ public protocol FetchableSource: class {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: the first `DynamicObject` instance that satisfies the specified `FetchClause`s
|
- returns: the first `DynamicObject` instance that satisfies the specified `FetchClause`s
|
||||||
*/
|
*/
|
||||||
func fetchOne<T: DynamicObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> T?
|
func fetchOne<T>(_ from: From<T>, _ fetchClauses: FetchClause...) -> T?
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Fetches the first `DynamicObject` instance that satisfies the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
Fetches the first `DynamicObject` instance that satisfies the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
@@ -82,7 +82,7 @@ public protocol FetchableSource: class {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: the first `DynamicObject` instance that satisfies the specified `FetchClause`s
|
- returns: the first `DynamicObject` instance that satisfies the specified `FetchClause`s
|
||||||
*/
|
*/
|
||||||
func fetchOne<T: DynamicObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> T?
|
func fetchOne<T>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> T?
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Fetches all `DynamicObject` instances that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
Fetches all `DynamicObject` instances that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
@@ -91,7 +91,7 @@ public protocol FetchableSource: class {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: all `DynamicObject` instances that satisfy the specified `FetchClause`s
|
- returns: all `DynamicObject` instances that satisfy the specified `FetchClause`s
|
||||||
*/
|
*/
|
||||||
func fetchAll<T: DynamicObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> [T]?
|
func fetchAll<T>(_ from: From<T>, _ fetchClauses: FetchClause...) -> [T]?
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Fetches all `DynamicObject` instances that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
Fetches all `DynamicObject` instances that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
@@ -100,7 +100,7 @@ public protocol FetchableSource: class {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: all `DynamicObject` instances that satisfy the specified `FetchClause`s
|
- returns: all `DynamicObject` instances that satisfy the specified `FetchClause`s
|
||||||
*/
|
*/
|
||||||
func fetchAll<T: DynamicObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> [T]?
|
func fetchAll<T>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> [T]?
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Fetches the number of `DynamicObject`s that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
Fetches the number of `DynamicObject`s that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
@@ -109,7 +109,7 @@ public protocol FetchableSource: class {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: the number `DynamicObject`s that satisfy the specified `FetchClause`s
|
- returns: the number `DynamicObject`s that satisfy the specified `FetchClause`s
|
||||||
*/
|
*/
|
||||||
func fetchCount<T: DynamicObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> Int?
|
func fetchCount<T>(_ from: From<T>, _ fetchClauses: FetchClause...) -> Int?
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Fetches the number of `DynamicObject`s that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
Fetches the number of `DynamicObject`s that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
@@ -118,7 +118,7 @@ public protocol FetchableSource: class {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: the number `DynamicObject`s that satisfy the specified `FetchClause`s
|
- returns: the number `DynamicObject`s that satisfy the specified `FetchClause`s
|
||||||
*/
|
*/
|
||||||
func fetchCount<T: DynamicObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> Int?
|
func fetchCount<T>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> Int?
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Fetches the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
Fetches the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
@@ -127,7 +127,7 @@ public protocol FetchableSource: class {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s
|
- returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s
|
||||||
*/
|
*/
|
||||||
func fetchObjectID<T: DynamicObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> NSManagedObjectID?
|
func fetchObjectID<T>(_ from: From<T>, _ fetchClauses: FetchClause...) -> NSManagedObjectID?
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Fetches the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
Fetches the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
@@ -136,7 +136,7 @@ public protocol FetchableSource: class {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s
|
- returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s
|
||||||
*/
|
*/
|
||||||
func fetchObjectID<T: DynamicObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> NSManagedObjectID?
|
func fetchObjectID<T>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> NSManagedObjectID?
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Fetches the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
Fetches the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
@@ -145,7 +145,7 @@ public protocol FetchableSource: class {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s
|
- returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s
|
||||||
*/
|
*/
|
||||||
func fetchObjectIDs<T: DynamicObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> [NSManagedObjectID]?
|
func fetchObjectIDs<T>(_ from: From<T>, _ fetchClauses: FetchClause...) -> [NSManagedObjectID]?
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Fetches the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
Fetches the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
@@ -154,7 +154,7 @@ public protocol FetchableSource: class {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s
|
- returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s
|
||||||
*/
|
*/
|
||||||
func fetchObjectIDs<T: DynamicObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> [NSManagedObjectID]?
|
func fetchObjectIDs<T>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> [NSManagedObjectID]?
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The internal `NSManagedObjectContext` managed by this `FetchableSource`. Using this context directly should typically be avoided, and is provided by CoreStore only for extremely specialized cases.
|
The internal `NSManagedObjectContext` managed by this `FetchableSource`. Using this context directly should typically be avoided, and is provided by CoreStore only for extremely specialized cases.
|
||||||
|
|||||||
@@ -185,6 +185,10 @@ internal final class FetchedResultsControllerDelegate: NSObject, NSFetchedResult
|
|||||||
)
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
guard #available(iOS 9.0, tvOS 9.0, watchOS 9.0, *) else {
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
self.handler?.controller(
|
self.handler?.controller(
|
||||||
controller,
|
controller,
|
||||||
didChangeObject: anObject,
|
didChangeObject: anObject,
|
||||||
|
|||||||
+2
-2
@@ -139,7 +139,7 @@ public struct From<T: DynamicObject> {
|
|||||||
self.findPersistentStores = findPersistentStores
|
self.findPersistentStores = findPersistentStores
|
||||||
}
|
}
|
||||||
|
|
||||||
internal func applyToFetchRequest<ResultType: NSFetchRequestResult>(_ fetchRequest: NSFetchRequest<ResultType>, context: NSManagedObjectContext, applyAffectedStores: Bool = true) -> Bool {
|
internal func applyToFetchRequest<ResultType>(_ fetchRequest: NSFetchRequest<ResultType>, context: NSManagedObjectContext, applyAffectedStores: Bool = true) -> Bool {
|
||||||
|
|
||||||
fetchRequest.entity = context.parentStack!.entityDescription(for: EntityIdentifier(self.entityClass))!
|
fetchRequest.entity = context.parentStack!.entityDescription(for: EntityIdentifier(self.entityClass))!
|
||||||
guard applyAffectedStores else {
|
guard applyAffectedStores else {
|
||||||
@@ -157,7 +157,7 @@ public struct From<T: DynamicObject> {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
internal func applyAffectedStoresForFetchedRequest<U: NSFetchRequestResult>(_ fetchRequest: NSFetchRequest<U>, context: NSManagedObjectContext) -> Bool {
|
internal func applyAffectedStoresForFetchedRequest<U>(_ fetchRequest: NSFetchRequest<U>, context: NSManagedObjectContext) -> Bool {
|
||||||
|
|
||||||
let stores = self.findPersistentStores(context)
|
let stores = self.findPersistentStores(context)
|
||||||
fetchRequest.affectedStores = stores
|
fetchRequest.affectedStores = stores
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ public struct GroupBy: QueryClause, Hashable {
|
|||||||
/**
|
/**
|
||||||
The list of key path strings to group results with
|
The list of key path strings to group results with
|
||||||
*/
|
*/
|
||||||
public let keyPaths: [KeyPath]
|
public let keyPaths: [RawKeyPath]
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Initializes a `GroupBy` clause with an empty list of key path strings
|
Initializes a `GroupBy` clause with an empty list of key path strings
|
||||||
@@ -53,7 +53,7 @@ public struct GroupBy: QueryClause, Hashable {
|
|||||||
- parameter keyPath: a key path string to group results with
|
- parameter keyPath: a key path string to group results with
|
||||||
- parameter keyPaths: a series of key path strings to group results with
|
- parameter keyPaths: a series of key path strings to group results with
|
||||||
*/
|
*/
|
||||||
public init(_ keyPath: KeyPath, _ keyPaths: KeyPath...) {
|
public init(_ keyPath: RawKeyPath, _ keyPaths: RawKeyPath...) {
|
||||||
|
|
||||||
self.init([keyPath] + keyPaths)
|
self.init([keyPath] + keyPaths)
|
||||||
}
|
}
|
||||||
@@ -63,7 +63,7 @@ public struct GroupBy: QueryClause, Hashable {
|
|||||||
|
|
||||||
- parameter keyPaths: a list of key path strings to group results with
|
- parameter keyPaths: a list of key path strings to group results with
|
||||||
*/
|
*/
|
||||||
public init(_ keyPaths: [KeyPath]) {
|
public init(_ keyPaths: [RawKeyPath]) {
|
||||||
|
|
||||||
self.keyPaths = keyPaths
|
self.keyPaths = keyPaths
|
||||||
}
|
}
|
||||||
@@ -71,7 +71,7 @@ public struct GroupBy: QueryClause, Hashable {
|
|||||||
|
|
||||||
// MARK: QueryClause
|
// MARK: QueryClause
|
||||||
|
|
||||||
public func applyToFetchRequest<ResultType: NSFetchRequestResult>(_ fetchRequest: NSFetchRequest<ResultType>) {
|
public func applyToFetchRequest<ResultType>(_ fetchRequest: NSFetchRequest<ResultType>) {
|
||||||
|
|
||||||
if let keyPaths = fetchRequest.propertiesToGroupBy as? [String], keyPaths != self.keyPaths {
|
if let keyPaths = fetchRequest.propertiesToGroupBy as? [String], keyPaths != self.keyPaths {
|
||||||
|
|
||||||
|
|||||||
@@ -425,8 +425,6 @@ public final class ICloudStore: CloudStorage {
|
|||||||
*/
|
*/
|
||||||
public func cs_eraseStorageAndWait(soureModel: NSManagedObjectModel) throws {
|
public func cs_eraseStorageAndWait(soureModel: NSManagedObjectModel) throws {
|
||||||
|
|
||||||
// TODO: check if attached to persistent store
|
|
||||||
|
|
||||||
let cacheFileURL = self.cacheFileURL
|
let cacheFileURL = self.cacheFileURL
|
||||||
try autoreleasepool {
|
try autoreleasepool {
|
||||||
|
|
||||||
|
|||||||
@@ -57,481 +57,121 @@ import CoreGraphics
|
|||||||
|
|
||||||
In addition, `RawRepresentable` types whose `RawValue` already implements `ImportableAttributeType` only need to declare conformance to `ImportableAttributeType`.
|
In addition, `RawRepresentable` types whose `RawValue` already implements `ImportableAttributeType` only need to declare conformance to `ImportableAttributeType`.
|
||||||
*/
|
*/
|
||||||
public protocol ImportableAttributeType: QueryableAttributeType {
|
public protocol ImportableAttributeType: QueryableAttributeType {}
|
||||||
|
|
||||||
/**
|
|
||||||
The `CoreDataNativeType` for this type.
|
|
||||||
*/
|
|
||||||
associatedtype ImportableNativeType: QueryableNativeType
|
|
||||||
|
|
||||||
/**
|
|
||||||
Creates an instance of this type from its `ImportableNativeType` value.
|
|
||||||
*/
|
|
||||||
@inline(__always)
|
|
||||||
static func cs_fromImportableNativeType(_ value: ImportableNativeType) -> Self?
|
|
||||||
|
|
||||||
/**
|
|
||||||
Creates `ImportableNativeType` value from this instance.
|
|
||||||
*/
|
|
||||||
@inline(__always)
|
|
||||||
func cs_toImportableNativeType() -> ImportableNativeType
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// MARK: - Bool
|
// MARK: - Bool
|
||||||
|
|
||||||
extension Bool: ImportableAttributeType {
|
extension Bool: ImportableAttributeType {}
|
||||||
|
|
||||||
// MARK: ImportableAttributeType
|
|
||||||
|
|
||||||
public typealias ImportableNativeType = NSNumber
|
|
||||||
|
|
||||||
@inline(__always)
|
|
||||||
public static func cs_fromImportableNativeType(_ value: ImportableNativeType) -> Bool? {
|
|
||||||
|
|
||||||
return self.cs_fromQueryableNativeType(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
@inline(__always)
|
|
||||||
public func cs_toImportableNativeType() -> ImportableNativeType {
|
|
||||||
|
|
||||||
return self.cs_toQueryableNativeType()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - CGFloat
|
// MARK: - CGFloat
|
||||||
|
|
||||||
extension CGFloat: ImportableAttributeType {
|
extension CGFloat: ImportableAttributeType {}
|
||||||
|
|
||||||
// MARK: ImportableAttributeType
|
|
||||||
|
|
||||||
public typealias ImportableNativeType = NSNumber
|
|
||||||
|
|
||||||
@inline(__always)
|
|
||||||
public static func cs_fromImportableNativeType(_ value: ImportableNativeType) -> CGFloat? {
|
|
||||||
|
|
||||||
return self.cs_fromQueryableNativeType(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
@inline(__always)
|
|
||||||
public func cs_toImportableNativeType() -> ImportableNativeType {
|
|
||||||
|
|
||||||
return self.cs_toQueryableNativeType()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// MARK: - Data
|
// MARK: - Data
|
||||||
|
|
||||||
extension Data: ImportableAttributeType {
|
extension Data: ImportableAttributeType {}
|
||||||
|
|
||||||
// MARK: ImportableAttributeType
|
|
||||||
|
|
||||||
public typealias ImportableNativeType = NSData
|
|
||||||
|
|
||||||
@inline(__always)
|
|
||||||
public static func cs_fromImportableNativeType(_ value: ImportableNativeType) -> Data? {
|
|
||||||
|
|
||||||
return self.cs_fromQueryableNativeType(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
@inline(__always)
|
|
||||||
public func cs_toImportableNativeType() -> ImportableNativeType {
|
|
||||||
|
|
||||||
return self.cs_toQueryableNativeType()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// MARK: - Date
|
// MARK: - Date
|
||||||
|
|
||||||
extension Date: ImportableAttributeType {
|
extension Date: ImportableAttributeType {}
|
||||||
|
|
||||||
// MARK: ImportableAttributeType
|
|
||||||
|
|
||||||
public typealias ImportableNativeType = NSDate
|
|
||||||
|
|
||||||
@inline(__always)
|
|
||||||
public static func cs_fromImportableNativeType(_ value: ImportableNativeType) -> Date? {
|
|
||||||
|
|
||||||
return self.cs_fromQueryableNativeType(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
@inline(__always)
|
|
||||||
public func cs_toImportableNativeType() -> ImportableNativeType {
|
|
||||||
|
|
||||||
return self.cs_toQueryableNativeType()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// MARK: - Double
|
// MARK: - Double
|
||||||
|
|
||||||
extension Double: ImportableAttributeType {
|
extension Double: ImportableAttributeType {}
|
||||||
|
|
||||||
// MARK: ImportableAttributeType
|
|
||||||
|
|
||||||
public typealias ImportableNativeType = NSNumber
|
|
||||||
|
|
||||||
@inline(__always)
|
|
||||||
public static func cs_fromImportableNativeType(_ value: ImportableNativeType) -> Double? {
|
|
||||||
|
|
||||||
return self.cs_fromQueryableNativeType(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
@inline(__always)
|
|
||||||
public func cs_toImportableNativeType() -> ImportableNativeType {
|
|
||||||
|
|
||||||
return self.cs_toQueryableNativeType()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// MARK: - Float
|
// MARK: - Float
|
||||||
|
|
||||||
extension Float: ImportableAttributeType {
|
extension Float: ImportableAttributeType {}
|
||||||
|
|
||||||
// MARK: ImportableAttributeType
|
|
||||||
|
|
||||||
public typealias ImportableNativeType = NSNumber
|
|
||||||
|
|
||||||
@inline(__always)
|
|
||||||
public static func cs_fromImportableNativeType(_ value: ImportableNativeType) -> Float? {
|
|
||||||
|
|
||||||
return self.cs_fromQueryableNativeType(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
@inline(__always)
|
|
||||||
public func cs_toImportableNativeType() -> ImportableNativeType {
|
|
||||||
|
|
||||||
return self.cs_toQueryableNativeType()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// MARK: - Int
|
// MARK: - Int
|
||||||
|
|
||||||
extension Int: ImportableAttributeType {
|
extension Int: ImportableAttributeType {}
|
||||||
|
|
||||||
// MARK: ImportableAttributeType
|
|
||||||
|
|
||||||
public typealias ImportableNativeType = NSNumber
|
|
||||||
|
|
||||||
@inline(__always)
|
|
||||||
public static func cs_fromImportableNativeType(_ value: ImportableNativeType) -> Int? {
|
|
||||||
|
|
||||||
return self.cs_fromQueryableNativeType(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
@inline(__always)
|
|
||||||
public func cs_toImportableNativeType() -> ImportableNativeType {
|
|
||||||
|
|
||||||
return self.cs_toQueryableNativeType()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// MARK: - Int8
|
// MARK: - Int8
|
||||||
|
|
||||||
extension Int8: ImportableAttributeType {
|
extension Int8: ImportableAttributeType {}
|
||||||
|
|
||||||
// MARK: ImportableAttributeType
|
|
||||||
|
|
||||||
public typealias ImportableNativeType = NSNumber
|
|
||||||
|
|
||||||
@inline(__always)
|
|
||||||
public static func cs_fromImportableNativeType(_ value: ImportableNativeType) -> Int8? {
|
|
||||||
|
|
||||||
return self.cs_fromQueryableNativeType(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
@inline(__always)
|
|
||||||
public func cs_toImportableNativeType() -> ImportableNativeType {
|
|
||||||
|
|
||||||
return self.cs_toQueryableNativeType()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// MARK: - Int16
|
// MARK: - Int16
|
||||||
|
|
||||||
extension Int16: ImportableAttributeType {
|
extension Int16: ImportableAttributeType {}
|
||||||
|
|
||||||
// MARK: ImportableAttributeType
|
|
||||||
|
|
||||||
public typealias ImportableNativeType = NSNumber
|
|
||||||
|
|
||||||
@inline(__always)
|
|
||||||
public static func cs_fromImportableNativeType(_ value: ImportableNativeType) -> Int16? {
|
|
||||||
|
|
||||||
return self.cs_fromQueryableNativeType(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
@inline(__always)
|
|
||||||
public func cs_toImportableNativeType() -> ImportableNativeType {
|
|
||||||
|
|
||||||
return self.cs_toQueryableNativeType()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// MARK: - Int32
|
// MARK: - Int32
|
||||||
|
|
||||||
extension Int32: ImportableAttributeType {
|
extension Int32: ImportableAttributeType {}
|
||||||
|
|
||||||
// MARK: ImportableAttributeType
|
|
||||||
|
|
||||||
public typealias ImportableNativeType = NSNumber
|
|
||||||
|
|
||||||
@inline(__always)
|
|
||||||
public static func cs_fromImportableNativeType(_ value: ImportableNativeType) -> Int32? {
|
|
||||||
|
|
||||||
return self.cs_fromQueryableNativeType(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
@inline(__always)
|
|
||||||
public func cs_toImportableNativeType() -> ImportableNativeType {
|
|
||||||
|
|
||||||
return self.cs_toQueryableNativeType()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// MARK: - Int64
|
// MARK: - Int64
|
||||||
|
|
||||||
extension Int64: ImportableAttributeType {
|
extension Int64: ImportableAttributeType {}
|
||||||
|
|
||||||
// MARK: ImportableAttributeType
|
|
||||||
|
|
||||||
public typealias ImportableNativeType = NSNumber
|
|
||||||
|
|
||||||
@inline(__always)
|
|
||||||
public static func cs_fromImportableNativeType(_ value: ImportableNativeType) -> Int64? {
|
|
||||||
|
|
||||||
return self.cs_fromQueryableNativeType(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
@inline(__always)
|
|
||||||
public func cs_toImportableNativeType() -> ImportableNativeType {
|
|
||||||
|
|
||||||
return self.cs_toQueryableNativeType()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// MARK: - NSData
|
// MARK: - NSData
|
||||||
|
|
||||||
extension NSData: ImportableAttributeType {
|
extension NSData: ImportableAttributeType {}
|
||||||
|
|
||||||
// MARK: ImportableAttributeType
|
|
||||||
|
|
||||||
public typealias ImportableNativeType = NSData
|
|
||||||
|
|
||||||
@nonobjc @inline(__always)
|
|
||||||
public class func cs_fromImportableNativeType(_ value: ImportableNativeType) -> Self? {
|
|
||||||
|
|
||||||
return self.cs_fromQueryableNativeType(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
@nonobjc @inline(__always)
|
|
||||||
public func cs_toImportableNativeType() -> ImportableNativeType {
|
|
||||||
|
|
||||||
return self.cs_toQueryableNativeType()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// MARK: - NSDate
|
// MARK: - NSDate
|
||||||
|
|
||||||
extension NSDate: ImportableAttributeType {
|
extension NSDate: ImportableAttributeType {}
|
||||||
|
|
||||||
// MARK: ImportableAttributeType
|
|
||||||
|
|
||||||
public typealias ImportableNativeType = NSDate
|
|
||||||
|
|
||||||
@nonobjc @inline(__always)
|
|
||||||
public class func cs_fromImportableNativeType(_ value: ImportableNativeType) -> Self? {
|
|
||||||
|
|
||||||
return self.cs_fromQueryableNativeType(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
@nonobjc @inline(__always)
|
|
||||||
public func cs_toImportableNativeType() -> ImportableNativeType {
|
|
||||||
|
|
||||||
return self.cs_toQueryableNativeType()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// MARK: - NSNumber
|
// MARK: - NSNumber
|
||||||
|
|
||||||
extension NSNumber: ImportableAttributeType {
|
extension NSNumber: ImportableAttributeType {}
|
||||||
|
|
||||||
// MARK: ImportableAttributeType
|
|
||||||
|
|
||||||
public typealias ImportableNativeType = NSNumber
|
|
||||||
|
|
||||||
@nonobjc @inline(__always)
|
|
||||||
public class func cs_fromImportableNativeType(_ value: ImportableNativeType) -> Self? {
|
|
||||||
|
|
||||||
return self.cs_fromQueryableNativeType(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
@nonobjc @inline(__always)
|
|
||||||
public func cs_toImportableNativeType() -> ImportableNativeType {
|
|
||||||
|
|
||||||
return self.cs_toQueryableNativeType()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// MARK: - NSString
|
// MARK: - NSString
|
||||||
|
|
||||||
extension NSString: ImportableAttributeType {
|
extension NSString: ImportableAttributeType {}
|
||||||
|
|
||||||
// MARK: ImportableAttributeType
|
|
||||||
|
|
||||||
public typealias ImportableNativeType = NSString
|
|
||||||
|
|
||||||
@nonobjc @inline(__always)
|
|
||||||
public class func cs_fromImportableNativeType(_ value: ImportableNativeType) -> Self? {
|
|
||||||
|
|
||||||
return self.cs_fromQueryableNativeType(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
@nonobjc @inline(__always)
|
|
||||||
public func cs_toImportableNativeType() -> ImportableNativeType {
|
|
||||||
|
|
||||||
return self.cs_toQueryableNativeType()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// MARK: - NSURL
|
// MARK: - NSURL
|
||||||
|
|
||||||
extension NSURL: ImportableAttributeType {
|
extension NSURL: ImportableAttributeType {}
|
||||||
|
|
||||||
// MARK: ImportableAttributeType
|
|
||||||
|
|
||||||
public typealias ImportableNativeType = NSString
|
|
||||||
|
|
||||||
@nonobjc @inline(__always)
|
|
||||||
public class func cs_fromImportableNativeType(_ value: ImportableNativeType) -> Self? {
|
|
||||||
|
|
||||||
return self.cs_fromQueryableNativeType(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
@nonobjc @inline(__always)
|
|
||||||
public func cs_toImportableNativeType() -> ImportableNativeType {
|
|
||||||
|
|
||||||
return self.cs_toQueryableNativeType()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// MARK: - NSUUID
|
// MARK: - NSUUID
|
||||||
|
|
||||||
extension NSUUID: ImportableAttributeType {
|
extension NSUUID: ImportableAttributeType {}
|
||||||
|
|
||||||
// MARK: ImportableAttributeType
|
|
||||||
|
|
||||||
public typealias ImportableNativeType = NSString
|
|
||||||
|
|
||||||
@nonobjc @inline(__always)
|
|
||||||
public class func cs_fromImportableNativeType(_ value: ImportableNativeType) -> Self? {
|
|
||||||
|
|
||||||
return self.cs_fromQueryableNativeType(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
@nonobjc @inline(__always)
|
|
||||||
public func cs_toImportableNativeType() -> ImportableNativeType {
|
|
||||||
|
|
||||||
return self.cs_toQueryableNativeType()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// MARK: - String
|
// MARK: - String
|
||||||
|
|
||||||
extension String: ImportableAttributeType {
|
extension String: ImportableAttributeType {}
|
||||||
|
|
||||||
// MARK: ImportableAttributeType
|
|
||||||
|
|
||||||
public typealias ImportableNativeType = NSString
|
|
||||||
|
|
||||||
@inline(__always)
|
|
||||||
public static func cs_fromImportableNativeType(_ value: ImportableNativeType) -> String? {
|
|
||||||
|
|
||||||
return self.cs_fromQueryableNativeType(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
@inline(__always)
|
|
||||||
public func cs_toImportableNativeType() -> ImportableNativeType {
|
|
||||||
|
|
||||||
return self.cs_toQueryableNativeType()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// MARK: - URL
|
// MARK: - URL
|
||||||
|
|
||||||
extension URL: ImportableAttributeType {
|
extension URL: ImportableAttributeType {}
|
||||||
|
|
||||||
// MARK: ImportableAttributeType
|
|
||||||
|
|
||||||
public typealias ImportableNativeType = NSString
|
|
||||||
|
|
||||||
@inline(__always)
|
|
||||||
public static func cs_fromImportableNativeType(_ value: ImportableNativeType) -> URL? {
|
|
||||||
|
|
||||||
return self.cs_fromQueryableNativeType(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
@inline(__always)
|
|
||||||
public func cs_toImportableNativeType() -> ImportableNativeType {
|
|
||||||
|
|
||||||
return self.cs_toQueryableNativeType()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// MARK: - UUID
|
// MARK: - UUID
|
||||||
|
|
||||||
extension UUID: ImportableAttributeType {
|
extension UUID: ImportableAttributeType {}
|
||||||
|
|
||||||
// MARK: ImportableAttributeType
|
|
||||||
|
|
||||||
public typealias ImportableNativeType = NSString
|
|
||||||
|
|
||||||
@inline(__always)
|
|
||||||
public static func cs_fromImportableNativeType(_ value: ImportableNativeType) -> UUID? {
|
|
||||||
|
|
||||||
return self.cs_fromQueryableNativeType(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
@inline(__always)
|
|
||||||
public func cs_toImportableNativeType() -> ImportableNativeType {
|
|
||||||
|
|
||||||
return self.cs_toQueryableNativeType()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// MARK: - RawRepresentable
|
// MARK: - RawRepresentable
|
||||||
|
|
||||||
extension RawRepresentable where RawValue: ImportableAttributeType {
|
extension RawRepresentable where RawValue: ImportableAttributeType {
|
||||||
|
|
||||||
public typealias ImportableNativeType = RawValue.ImportableNativeType
|
|
||||||
|
|
||||||
@inline(__always)
|
@inline(__always)
|
||||||
public static func cs_fromImportableNativeType(_ value: ImportableNativeType) -> Self? {
|
public static func cs_fromQueryableNativeType(_ value: QueryableNativeType) -> Self? {
|
||||||
|
|
||||||
return RawValue.cs_fromImportableNativeType(value).flatMap({ self.init(rawValue: $0) })
|
return RawValue.cs_fromQueryableNativeType(value).flatMap({ self.init(rawValue: $0) })
|
||||||
}
|
}
|
||||||
|
|
||||||
@inline(__always)
|
@inline(__always)
|
||||||
public func cs_toImportableNativeType() -> ImportableNativeType {
|
public func cs_toQueryableNativeType() -> QueryableNativeType {
|
||||||
|
|
||||||
return self.rawValue.cs_toImportableNativeType()
|
return self.rawValue.cs_toQueryableNativeType()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,11 +55,6 @@ import CoreData
|
|||||||
*/
|
*/
|
||||||
public protocol ImportableUniqueObject: ImportableObject {
|
public protocol ImportableUniqueObject: ImportableObject {
|
||||||
|
|
||||||
/**
|
|
||||||
The data type for the import source. This is most commonly an json type, `NSDictionary`, or another external source such as `NSUserDefaults`.
|
|
||||||
*/
|
|
||||||
associatedtype ImportSource
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The data type for the entity's unique ID attribute
|
The data type for the entity's unique ID attribute
|
||||||
*/
|
*/
|
||||||
@@ -123,6 +118,29 @@ public protocol ImportableUniqueObject: ImportableObject {
|
|||||||
|
|
||||||
// MARK: - ImportableUniqueObject (Default Implementations)
|
// MARK: - ImportableUniqueObject (Default Implementations)
|
||||||
|
|
||||||
|
public extension ImportableUniqueObject where UniqueIDType.QueryableNativeType: CoreDataNativeType {
|
||||||
|
|
||||||
|
var uniqueIDValue: UniqueIDType {
|
||||||
|
|
||||||
|
get {
|
||||||
|
|
||||||
|
return self.cs_toRaw().getValue(
|
||||||
|
forKvcKey: type(of: self).uniqueIDKeyPath,
|
||||||
|
didGetValue: { UniqueIDType.cs_fromQueryableNativeType($0 as! UniqueIDType.QueryableNativeType)! }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
|
||||||
|
self.cs_toRaw()
|
||||||
|
.setValue(
|
||||||
|
newValue,
|
||||||
|
forKvcKey: type(of: self).uniqueIDKeyPath,
|
||||||
|
willSetValue: { ($0.cs_toQueryableNativeType() as CoreDataNativeType) }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public extension ImportableUniqueObject {
|
public extension ImportableUniqueObject {
|
||||||
|
|
||||||
static func shouldInsert(from source: ImportSource, in transaction: BaseDataTransaction) -> Bool {
|
static func shouldInsert(from source: ImportSource, in transaction: BaseDataTransaction) -> Bool {
|
||||||
@@ -173,29 +191,3 @@ public extension ImportableUniqueObject {
|
|||||||
try self.update(from: source, in: transaction)
|
try self.update(from: source, in: transaction)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// MARK: - ImportableUniqueObject (Default Implementations)
|
|
||||||
|
|
||||||
public extension ImportableUniqueObject where Self: DynamicObject {
|
|
||||||
|
|
||||||
var uniqueIDValue: UniqueIDType {
|
|
||||||
|
|
||||||
get {
|
|
||||||
|
|
||||||
return self.cs_toRaw().getValue(
|
|
||||||
forKvcKey: type(of: self).uniqueIDKeyPath,
|
|
||||||
didGetValue: { UniqueIDType.cs_fromImportableNativeType($0 as! UniqueIDType.ImportableNativeType)! }
|
|
||||||
)
|
|
||||||
}
|
|
||||||
set {
|
|
||||||
|
|
||||||
self.cs_toRaw()
|
|
||||||
.setValue(
|
|
||||||
newValue,
|
|
||||||
forKvcKey: type(of: self).uniqueIDKeyPath,
|
|
||||||
willSetValue: { ($0.cs_toImportableNativeType() as! CoreDataNativeType) }
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
+1
-1
@@ -15,7 +15,7 @@
|
|||||||
<key>CFBundlePackageType</key>
|
<key>CFBundlePackageType</key>
|
||||||
<string>FMWK</string>
|
<string>FMWK</string>
|
||||||
<key>CFBundleShortVersionString</key>
|
<key>CFBundleShortVersionString</key>
|
||||||
<string>4.1.4</string>
|
<string>4.2.0</string>
|
||||||
<key>CFBundleSignature</key>
|
<key>CFBundleSignature</key>
|
||||||
<string>????</string>
|
<string>????</string>
|
||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
|
|||||||
+1
-1
@@ -103,7 +103,7 @@ public struct Into<T: DynamicObject>: Hashable {
|
|||||||
|
|
||||||
// MARK: Equatable
|
// MARK: Equatable
|
||||||
|
|
||||||
public static func == <U: DynamicObject, V: DynamicObject>(lhs: Into<U>, rhs: Into<V>) -> Bool {
|
public static func == <U, V>(lhs: Into<U>, rhs: Into<V>) -> Bool {
|
||||||
|
|
||||||
return lhs.entityClass == rhs.entityClass
|
return lhs.entityClass == rhs.entityClass
|
||||||
&& lhs.configuration == rhs.configuration
|
&& lhs.configuration == rhs.configuration
|
||||||
|
|||||||
@@ -600,7 +600,7 @@ public final class ListMonitor<D: DynamicObject>: Hashable {
|
|||||||
return lhs.fetchedResultsController === rhs.fetchedResultsController
|
return lhs.fetchedResultsController === rhs.fetchedResultsController
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func == <T: DynamicObject, U: DynamicObject>(lhs: ListMonitor<T>, rhs: ListMonitor<U>) -> Bool {
|
public static func == <T, U>(lhs: ListMonitor<T>, rhs: ListMonitor<U>) -> Bool {
|
||||||
|
|
||||||
return lhs.fetchedResultsController === rhs.fetchedResultsController
|
return lhs.fetchedResultsController === rhs.fetchedResultsController
|
||||||
}
|
}
|
||||||
@@ -610,7 +610,7 @@ public final class ListMonitor<D: DynamicObject>: Hashable {
|
|||||||
return lhs.fetchedResultsController === rhs.fetchedResultsController
|
return lhs.fetchedResultsController === rhs.fetchedResultsController
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func ~= <T: DynamicObject, U: DynamicObject>(lhs: ListMonitor<T>, rhs: ListMonitor<U>) -> Bool {
|
public static func ~= <T, U>(lhs: ListMonitor<T>, rhs: ListMonitor<U>) -> Bool {
|
||||||
|
|
||||||
return lhs.fetchedResultsController === rhs.fetchedResultsController
|
return lhs.fetchedResultsController === rhs.fetchedResultsController
|
||||||
}
|
}
|
||||||
@@ -997,7 +997,7 @@ public final class ListMonitor<D: DynamicObject>: Hashable {
|
|||||||
|
|
||||||
fileprivate var fetchedResultsController: CoreStoreFetchedResultsController
|
fileprivate var fetchedResultsController: CoreStoreFetchedResultsController
|
||||||
fileprivate let taskGroup = DispatchGroup()
|
fileprivate let taskGroup = DispatchGroup()
|
||||||
fileprivate let sectionIndexTransformer: (_ sectionName: KeyPath?) -> String?
|
fileprivate let sectionIndexTransformer: (_ sectionName: RawKeyPath?) -> String?
|
||||||
|
|
||||||
private let isSectioned: Bool
|
private let isSectioned: Bool
|
||||||
|
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ public struct MigrationChain: ExpressibleByNilLiteral, ExpressibleByStringLitera
|
|||||||
/**
|
/**
|
||||||
Initializes the `MigrationChain` with a linear order of versions, which becomes the order of the `DataStack`'s progressive migrations.
|
Initializes the `MigrationChain` with a linear order of versions, which becomes the order of the `DataStack`'s progressive migrations.
|
||||||
*/
|
*/
|
||||||
public init<T: Collection>(_ elements: T) where T.Iterator.Element == String, T.SubSequence.Iterator.Element == String, T.Index: Comparable {
|
public init<T: Collection>(_ elements: T) where T.Iterator.Element == String {
|
||||||
|
|
||||||
CoreStore.assert(Set(elements).count == Array(elements).count, "\(cs_typeName(MigrationChain.self))'s migration chain could not be created due to duplicate version strings.")
|
CoreStore.assert(Set(elements).count == Array(elements).count, "\(cs_typeName(MigrationChain.self))'s migration chain could not be created due to duplicate version strings.")
|
||||||
|
|
||||||
|
|||||||
@@ -87,14 +87,14 @@ internal extension NSEntityDescription {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
internal var keyPathsByAffectedKeyPaths: [KeyPath: Set<KeyPath>] {
|
internal var keyPathsByAffectedKeyPaths: [RawKeyPath: Set<RawKeyPath>] {
|
||||||
|
|
||||||
get {
|
get {
|
||||||
|
|
||||||
if let userInfo = self.userInfo,
|
if let userInfo = self.userInfo,
|
||||||
let value = userInfo[UserInfoKey.CoreStoreManagedObjectKeyPathsByAffectedKeyPaths] {
|
let value = userInfo[UserInfoKey.CoreStoreManagedObjectKeyPathsByAffectedKeyPaths] {
|
||||||
|
|
||||||
return value as! [KeyPath: Set<KeyPath>]
|
return value as! [RawKeyPath: Set<RawKeyPath>]
|
||||||
}
|
}
|
||||||
return [:]
|
return [:]
|
||||||
}
|
}
|
||||||
@@ -108,14 +108,14 @@ internal extension NSEntityDescription {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
internal var customGetterSetterByKeyPaths: [KeyPath: CoreStoreManagedObject.CustomGetterSetter] {
|
internal var customGetterSetterByKeyPaths: [RawKeyPath: CoreStoreManagedObject.CustomGetterSetter] {
|
||||||
|
|
||||||
get {
|
get {
|
||||||
|
|
||||||
if let userInfo = self.userInfo,
|
if let userInfo = self.userInfo,
|
||||||
let value = userInfo[UserInfoKey.CoreStoreManagedObjectCustomGetterSetterByKeyPaths] {
|
let value = userInfo[UserInfoKey.CoreStoreManagedObjectCustomGetterSetterByKeyPaths] {
|
||||||
|
|
||||||
return value as! [KeyPath: CoreStoreManagedObject.CustomGetterSetter]
|
return value as! [RawKeyPath: CoreStoreManagedObject.CustomGetterSetter]
|
||||||
}
|
}
|
||||||
return [:]
|
return [:]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ public extension NSManagedObject {
|
|||||||
- returns: the primitive value for the KVC key
|
- returns: the primitive value for the KVC key
|
||||||
*/
|
*/
|
||||||
@nonobjc @inline(__always)
|
@nonobjc @inline(__always)
|
||||||
public func getValue(forKvcKey kvcKey: KeyPath) -> Any? {
|
public func getValue(forKvcKey kvcKey: RawKeyPath) -> Any? {
|
||||||
|
|
||||||
self.willAccessValue(forKey: kvcKey)
|
self.willAccessValue(forKey: kvcKey)
|
||||||
defer {
|
defer {
|
||||||
@@ -102,7 +102,7 @@ public extension NSManagedObject {
|
|||||||
- returns: the primitive value transformed by the `didGetValue` closure
|
- returns: the primitive value transformed by the `didGetValue` closure
|
||||||
*/
|
*/
|
||||||
@nonobjc @inline(__always)
|
@nonobjc @inline(__always)
|
||||||
public func getValue<T>(forKvcKey kvcKey: KeyPath, didGetValue: (Any?) throws -> T) rethrows -> T {
|
public func getValue<T>(forKvcKey kvcKey: RawKeyPath, didGetValue: (Any?) throws -> T) rethrows -> T {
|
||||||
|
|
||||||
self.willAccessValue(forKey: kvcKey)
|
self.willAccessValue(forKey: kvcKey)
|
||||||
defer {
|
defer {
|
||||||
@@ -121,7 +121,7 @@ public extension NSManagedObject {
|
|||||||
- returns: the primitive value transformed by the `didGetValue` closure
|
- returns: the primitive value transformed by the `didGetValue` closure
|
||||||
*/
|
*/
|
||||||
@nonobjc @inline(__always)
|
@nonobjc @inline(__always)
|
||||||
public func getValue<T>(forKvcKey kvcKey: KeyPath, willGetValue: () throws -> Void, didGetValue: (Any?) throws -> T) rethrows -> T {
|
public func getValue<T>(forKvcKey kvcKey: RawKeyPath, willGetValue: () throws -> Void, didGetValue: (Any?) throws -> T) rethrows -> T {
|
||||||
|
|
||||||
self.willAccessValue(forKey: kvcKey)
|
self.willAccessValue(forKey: kvcKey)
|
||||||
defer {
|
defer {
|
||||||
@@ -139,7 +139,7 @@ public extension NSManagedObject {
|
|||||||
- parameter KVCKey: the KVC key
|
- parameter KVCKey: the KVC key
|
||||||
*/
|
*/
|
||||||
@nonobjc @inline(__always)
|
@nonobjc @inline(__always)
|
||||||
public func setValue(_ value: Any?, forKvcKey KVCKey: KeyPath) {
|
public func setValue(_ value: Any?, forKvcKey KVCKey: RawKeyPath) {
|
||||||
|
|
||||||
self.willChangeValue(forKey: KVCKey)
|
self.willChangeValue(forKey: KVCKey)
|
||||||
defer {
|
defer {
|
||||||
@@ -157,7 +157,7 @@ public extension NSManagedObject {
|
|||||||
- parameter didSetValue: called after executing `setPrimitiveValue(forKey:)`.
|
- parameter didSetValue: called after executing `setPrimitiveValue(forKey:)`.
|
||||||
*/
|
*/
|
||||||
@nonobjc @inline(__always)
|
@nonobjc @inline(__always)
|
||||||
public func setValue(_ value: Any?, forKvcKey KVCKey: KeyPath, didSetValue: () -> Void) {
|
public func setValue(_ value: Any?, forKvcKey KVCKey: RawKeyPath, didSetValue: () -> Void) {
|
||||||
|
|
||||||
self.willChangeValue(forKey: KVCKey)
|
self.willChangeValue(forKey: KVCKey)
|
||||||
defer {
|
defer {
|
||||||
@@ -177,7 +177,7 @@ public extension NSManagedObject {
|
|||||||
- parameter didSetValue: called after executing `setPrimitiveValue(forKey:)`.
|
- parameter didSetValue: called after executing `setPrimitiveValue(forKey:)`.
|
||||||
*/
|
*/
|
||||||
@nonobjc @inline(__always)
|
@nonobjc @inline(__always)
|
||||||
public func setValue<T>(_ value: T, forKvcKey KVCKey: KeyPath, willSetValue: (T) throws -> Any?, didSetValue: (Any?) -> Void = { _ in }) rethrows {
|
public func setValue<T>(_ value: T, forKvcKey KVCKey: RawKeyPath, willSetValue: (T) throws -> Any?, didSetValue: (Any?) -> Void = { _ in }) rethrows {
|
||||||
|
|
||||||
self.willChangeValue(forKey: KVCKey)
|
self.willChangeValue(forKey: KVCKey)
|
||||||
defer {
|
defer {
|
||||||
@@ -212,7 +212,7 @@ public extension NSManagedObject {
|
|||||||
|
|
||||||
@available(*, deprecated, renamed: "getValue(forKvcKey:)")
|
@available(*, deprecated, renamed: "getValue(forKvcKey:)")
|
||||||
@nonobjc
|
@nonobjc
|
||||||
public func accessValueForKVCKey(_ KVCKey: KeyPath) -> Any? {
|
public func accessValueForKVCKey(_ KVCKey: RawKeyPath) -> Any? {
|
||||||
|
|
||||||
self.willAccessValue(forKey: KVCKey)
|
self.willAccessValue(forKey: KVCKey)
|
||||||
defer {
|
defer {
|
||||||
@@ -225,7 +225,7 @@ public extension NSManagedObject {
|
|||||||
@available(*, deprecated, renamed: "getValue(forKvcKey:didGetValue:)")
|
@available(*, deprecated, renamed: "getValue(forKvcKey:didGetValue:)")
|
||||||
@discardableResult
|
@discardableResult
|
||||||
@nonobjc
|
@nonobjc
|
||||||
public func accessValueForKVCKey<T>(_ KVCKey: KeyPath, _ didAccessPrimitiveValue: (Any?) throws -> T) rethrows -> T {
|
public func accessValueForKVCKey<T>(_ KVCKey: RawKeyPath, _ didAccessPrimitiveValue: (Any?) throws -> T) rethrows -> T {
|
||||||
|
|
||||||
self.willAccessValue(forKey: KVCKey)
|
self.willAccessValue(forKey: KVCKey)
|
||||||
defer {
|
defer {
|
||||||
@@ -237,7 +237,7 @@ public extension NSManagedObject {
|
|||||||
|
|
||||||
@available(*, deprecated, renamed: "setValue(_:forKvcKey:)")
|
@available(*, deprecated, renamed: "setValue(_:forKvcKey:)")
|
||||||
@nonobjc
|
@nonobjc
|
||||||
public func setValue(_ value: Any?, forKVCKey KVCKey: KeyPath) {
|
public func setValue(_ value: Any?, forKVCKey KVCKey: RawKeyPath) {
|
||||||
|
|
||||||
self.willChangeValue(forKey: KVCKey)
|
self.willChangeValue(forKey: KVCKey)
|
||||||
defer {
|
defer {
|
||||||
@@ -250,7 +250,7 @@ public extension NSManagedObject {
|
|||||||
@available(*, deprecated, renamed: "setValue(_:forKvcKey:didSetValue:)")
|
@available(*, deprecated, renamed: "setValue(_:forKvcKey:didSetValue:)")
|
||||||
@discardableResult
|
@discardableResult
|
||||||
@nonobjc
|
@nonobjc
|
||||||
public func setValue<T>(_ value: Any?, forKVCKey KVCKey: KeyPath, _ didSetPrimitiveValue: (Any?) throws -> T) rethrows -> T {
|
public func setValue<T>(_ value: Any?, forKVCKey KVCKey: RawKeyPath, _ didSetPrimitiveValue: (Any?) throws -> T) rethrows -> T {
|
||||||
|
|
||||||
self.willChangeValue(forKey: KVCKey)
|
self.willChangeValue(forKey: KVCKey)
|
||||||
defer {
|
defer {
|
||||||
|
|||||||
@@ -66,212 +66,4 @@ internal extension NSManagedObject {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: test before release (rolled back)
|
|
||||||
// @nonobjc
|
|
||||||
// internal static func cs_swizzleMethodsForLogging() {
|
|
||||||
//
|
|
||||||
// struct Static {
|
|
||||||
//
|
|
||||||
// static let isSwizzled = Static.swizzle()
|
|
||||||
//
|
|
||||||
// private static func swizzle() -> Bool {
|
|
||||||
//
|
|
||||||
// NSManagedObject.cs_swizzle(
|
|
||||||
// original: #selector(NSManagedObject.willAccessValue(forKey:)),
|
|
||||||
// proxy: #selector(NSManagedObject.cs_willAccessValue(forKey:))
|
|
||||||
// )
|
|
||||||
// NSManagedObject.cs_swizzle(
|
|
||||||
// original: #selector(NSManagedObject.willChangeValue(forKey:)),
|
|
||||||
// proxy: #selector(NSManagedObject.cs_willChangeValue(forKey:))
|
|
||||||
// )
|
|
||||||
// NSManagedObject.cs_swizzle(
|
|
||||||
// original: #selector(NSManagedObject.willChangeValue(forKey:withSetMutation:using:)),
|
|
||||||
// proxy: #selector(NSManagedObject.cs_willChangeValue(forKey:withSetMutation:using:))
|
|
||||||
// )
|
|
||||||
// return true
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// assert(Static.isSwizzled)
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @nonobjc
|
|
||||||
// private static func cs_swizzle(original originalSelector: Selector, proxy swizzledSelector: Selector) {
|
|
||||||
//
|
|
||||||
// let originalMethod = class_getInstanceMethod(NSManagedObject.self, originalSelector)
|
|
||||||
// let swizzledMethod = class_getInstanceMethod(NSManagedObject.self, swizzledSelector)
|
|
||||||
// let didAddMethod = class_addMethod(
|
|
||||||
// NSManagedObject.self,
|
|
||||||
// originalSelector,
|
|
||||||
// method_getImplementation(swizzledMethod),
|
|
||||||
// method_getTypeEncoding(swizzledMethod)
|
|
||||||
// )
|
|
||||||
// if didAddMethod {
|
|
||||||
//
|
|
||||||
// class_replaceMethod(
|
|
||||||
// NSManagedObject.self,
|
|
||||||
// swizzledSelector,
|
|
||||||
// method_getImplementation(originalMethod),
|
|
||||||
// method_getTypeEncoding(originalMethod)
|
|
||||||
// )
|
|
||||||
// }
|
|
||||||
// else {
|
|
||||||
//
|
|
||||||
// method_exchangeImplementations(originalMethod, swizzledMethod)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// private dynamic func cs_willAccessValue(forKey key: String?) {
|
|
||||||
//
|
|
||||||
// self.cs_willAccessValue(forKey: key)
|
|
||||||
//
|
|
||||||
// guard CoreStore.logger.enableObjectConcurrencyDebugging else {
|
|
||||||
//
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// guard let context = self.managedObjectContext else {
|
|
||||||
//
|
|
||||||
// CoreStore.log(
|
|
||||||
// .warning,
|
|
||||||
// message: "Attempted to access the \"\(key ?? "")\" key of an object of type \(cs_typeName(self)) after has been deleted from its \(cs_typeName(NSManagedObjectContext.self))."
|
|
||||||
// )
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// if context.isTransactionContext {
|
|
||||||
//
|
|
||||||
// guard let transaction = context.parentTransaction else {
|
|
||||||
//
|
|
||||||
// CoreStore.log(
|
|
||||||
// .warning,
|
|
||||||
// message: "Attempted to access the \"\(key ?? "")\" key of an object of type \(cs_typeName(self)) after has been deleted from its transaction."
|
|
||||||
// )
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// CoreStore.assert(
|
|
||||||
// transaction.isRunningInAllowedQueue(),
|
|
||||||
// "Attempted to access the \"\(key ?? "")\" key of an object of type \(cs_typeName(self)) outside its transaction's designated queue."
|
|
||||||
// )
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// if context.isDataStackContext {
|
|
||||||
//
|
|
||||||
// guard context.parentStack != nil else {
|
|
||||||
//
|
|
||||||
// CoreStore.log(
|
|
||||||
// .warning,
|
|
||||||
// message: "Attempted to access the \"\(key ?? "")\" key of an object of type \(cs_typeName(self)) after has been deleted from its \(cs_typeName(DataStack.self)).")
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// CoreStore.assert(
|
|
||||||
// Thread.isMainThread,
|
|
||||||
// "Attempted to access the \"\(key ?? "")\" key of an object of type \(cs_typeName(self)) outside the main thread."
|
|
||||||
// )
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// private dynamic func cs_willChangeValue(forKey key: String?) {
|
|
||||||
//
|
|
||||||
// self.cs_willChangeValue(forKey: key)
|
|
||||||
//
|
|
||||||
// guard CoreStore.logger.enableObjectConcurrencyDebugging else {
|
|
||||||
//
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// guard let context = self.managedObjectContext else {
|
|
||||||
//
|
|
||||||
// CoreStore.log(
|
|
||||||
// .warning,
|
|
||||||
// message: "Attempted to change the \"\(key ?? "")\" of an object of type \(cs_typeName(self)) after has been deleted from its \(cs_typeName(NSManagedObjectContext.self))."
|
|
||||||
// )
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// if context.isTransactionContext {
|
|
||||||
//
|
|
||||||
// guard let transaction = context.parentTransaction else {
|
|
||||||
//
|
|
||||||
// CoreStore.log(
|
|
||||||
// .warning,
|
|
||||||
// message: "Attempted to change the \"\(key ?? "")\" of an object of type \(cs_typeName(self)) after has been deleted from its transaction."
|
|
||||||
// )
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// CoreStore.assert(
|
|
||||||
// transaction.isRunningInAllowedQueue(),
|
|
||||||
// "Attempted to change the \"\(key ?? "")\" of an object of type \(cs_typeName(self)) outside its transaction's designated queue."
|
|
||||||
// )
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// if context.isDataStackContext {
|
|
||||||
//
|
|
||||||
// guard context.parentStack != nil else {
|
|
||||||
//
|
|
||||||
// CoreStore.log(
|
|
||||||
// .warning,
|
|
||||||
// message: "Attempted to change the \"\(key ?? "")\" of an object of type \(cs_typeName(self)) after has been deleted from its \(cs_typeName(DataStack.self)).")
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// CoreStore.assert(
|
|
||||||
// Thread.isMainThread,
|
|
||||||
// "Attempted to change the \"\(key ?? "")\" of an object of type \(cs_typeName(self)) outside the main thread."
|
|
||||||
// )
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// private dynamic func cs_willChangeValue(forKey inKey: String, withSetMutation inMutationKind: NSKeyValueSetMutationKind, using inObjects: Set<AnyHashable>) {
|
|
||||||
//
|
|
||||||
// self.cs_willChangeValue(
|
|
||||||
// forKey: inKey,
|
|
||||||
// withSetMutation: inMutationKind,
|
|
||||||
// using: inObjects
|
|
||||||
// )
|
|
||||||
//
|
|
||||||
// guard CoreStore.logger.enableObjectConcurrencyDebugging else {
|
|
||||||
//
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// guard let context = self.managedObjectContext else {
|
|
||||||
//
|
|
||||||
// CoreStore.log(
|
|
||||||
// .warning,
|
|
||||||
// message: "Attempted to mutate the \"\(inKey)\" of an object of type \(cs_typeName(self)) after has been deleted from its \(cs_typeName(NSManagedObjectContext.self))."
|
|
||||||
// )
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// if context.isTransactionContext {
|
|
||||||
//
|
|
||||||
// guard let transaction = context.parentTransaction else {
|
|
||||||
//
|
|
||||||
// CoreStore.log(
|
|
||||||
// .warning,
|
|
||||||
// message: "Attempted to mutate the \"\(inKey)\" of an object of type \(cs_typeName(self)) after has been deleted from its transaction."
|
|
||||||
// )
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// CoreStore.assert(
|
|
||||||
// transaction.isRunningInAllowedQueue(),
|
|
||||||
// "Attempted to mutate the \"\(inKey)\" of an object of type \(cs_typeName(self)) outside its transaction's designated queue."
|
|
||||||
// )
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// if context.isDataStackContext {
|
|
||||||
//
|
|
||||||
// guard context.parentStack != nil else {
|
|
||||||
//
|
|
||||||
// CoreStore.log(
|
|
||||||
// .warning,
|
|
||||||
// message: "Attempted to mutate the \"\(inKey)\" of an object of type \(cs_typeName(self)) after has been deleted from its \(cs_typeName(DataStack.self)).")
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// CoreStore.assert(
|
|
||||||
// Thread.isMainThread,
|
|
||||||
// "Attempted to mutate the \"\(inKey)\" of an object of type \(cs_typeName(self)) outside the main thread."
|
|
||||||
// )
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ public extension NSManagedObject {
|
|||||||
- returns: the primitive value for the KVC key
|
- returns: the primitive value for the KVC key
|
||||||
*/
|
*/
|
||||||
@objc
|
@objc
|
||||||
public func cs_accessValueForKVCKey(_ KVCKey: KeyPath) -> Any? {
|
public func cs_accessValueForKVCKey(_ KVCKey: RawKeyPath) -> Any? {
|
||||||
|
|
||||||
return self.getValue(forKvcKey: KVCKey)
|
return self.getValue(forKvcKey: KVCKey)
|
||||||
}
|
}
|
||||||
@@ -50,7 +50,7 @@ public extension NSManagedObject {
|
|||||||
- parameter KVCKey: the KVC key
|
- parameter KVCKey: the KVC key
|
||||||
*/
|
*/
|
||||||
@objc
|
@objc
|
||||||
public func cs_setValue(_ value: Any?, forKVCKey KVCKey: KeyPath) {
|
public func cs_setValue(_ value: Any?, forKVCKey KVCKey: RawKeyPath) {
|
||||||
|
|
||||||
self.setValue(value, forKvcKey: KVCKey)
|
self.setValue(value, forKvcKey: KVCKey)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -101,13 +101,13 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
public func fetchOne<T: DynamicObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> T? {
|
public func fetchOne<T>(_ from: From<T>, _ fetchClauses: FetchClause...) -> T? {
|
||||||
|
|
||||||
return self.fetchOne(from, fetchClauses)
|
return self.fetchOne(from, fetchClauses)
|
||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
public func fetchOne<T: DynamicObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> T? {
|
public func fetchOne<T>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> T? {
|
||||||
|
|
||||||
let fetchRequest = CoreStoreFetchRequest()
|
let fetchRequest = CoreStoreFetchRequest()
|
||||||
let storeFound = from.applyToFetchRequest(fetchRequest, context: self)
|
let storeFound = from.applyToFetchRequest(fetchRequest, context: self)
|
||||||
@@ -124,13 +124,13 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
public func fetchAll<T: DynamicObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> [T]? {
|
public func fetchAll<T>(_ from: From<T>, _ fetchClauses: FetchClause...) -> [T]? {
|
||||||
|
|
||||||
return self.fetchAll(from, fetchClauses)
|
return self.fetchAll(from, fetchClauses)
|
||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
public func fetchAll<T: DynamicObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> [T]? {
|
public func fetchAll<T>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> [T]? {
|
||||||
|
|
||||||
let fetchRequest = CoreStoreFetchRequest()
|
let fetchRequest = CoreStoreFetchRequest()
|
||||||
let storeFound = from.applyToFetchRequest(fetchRequest, context: self)
|
let storeFound = from.applyToFetchRequest(fetchRequest, context: self)
|
||||||
@@ -148,13 +148,13 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
public func fetchCount<T: DynamicObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> Int? {
|
public func fetchCount<T>(_ from: From<T>, _ fetchClauses: FetchClause...) -> Int? {
|
||||||
|
|
||||||
return self.fetchCount(from, fetchClauses)
|
return self.fetchCount(from, fetchClauses)
|
||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
public func fetchCount<T: DynamicObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> Int? {
|
public func fetchCount<T>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> Int? {
|
||||||
|
|
||||||
let fetchRequest = CoreStoreFetchRequest()
|
let fetchRequest = CoreStoreFetchRequest()
|
||||||
let storeFound = from.applyToFetchRequest(fetchRequest, context: self)
|
let storeFound = from.applyToFetchRequest(fetchRequest, context: self)
|
||||||
@@ -168,13 +168,13 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
public func fetchObjectID<T: DynamicObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> NSManagedObjectID? {
|
public func fetchObjectID<T>(_ from: From<T>, _ fetchClauses: FetchClause...) -> NSManagedObjectID? {
|
||||||
|
|
||||||
return self.fetchObjectID(from, fetchClauses)
|
return self.fetchObjectID(from, fetchClauses)
|
||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
public func fetchObjectID<T: DynamicObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> NSManagedObjectID? {
|
public func fetchObjectID<T>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> NSManagedObjectID? {
|
||||||
|
|
||||||
let fetchRequest = CoreStoreFetchRequest()
|
let fetchRequest = CoreStoreFetchRequest()
|
||||||
let storeFound = from.applyToFetchRequest(fetchRequest, context: self)
|
let storeFound = from.applyToFetchRequest(fetchRequest, context: self)
|
||||||
@@ -191,13 +191,13 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
public func fetchObjectIDs<T: DynamicObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> [NSManagedObjectID]? {
|
public func fetchObjectIDs<T>(_ from: From<T>, _ fetchClauses: FetchClause...) -> [NSManagedObjectID]? {
|
||||||
|
|
||||||
return self.fetchObjectIDs(from, fetchClauses)
|
return self.fetchObjectIDs(from, fetchClauses)
|
||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
public func fetchObjectIDs<T: DynamicObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> [NSManagedObjectID]? {
|
public func fetchObjectIDs<T>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> [NSManagedObjectID]? {
|
||||||
|
|
||||||
let fetchRequest = CoreStoreFetchRequest()
|
let fetchRequest = CoreStoreFetchRequest()
|
||||||
let storeFound = from.applyToFetchRequest(fetchRequest, context: self)
|
let storeFound = from.applyToFetchRequest(fetchRequest, context: self)
|
||||||
@@ -244,13 +244,13 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource {
|
|||||||
// MARK: QueryableSource
|
// MARK: QueryableSource
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
public func queryValue<T: DynamicObject, U: QueryableAttributeType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: QueryClause...) -> U? {
|
public func queryValue<T, U: QueryableAttributeType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: QueryClause...) -> U? {
|
||||||
|
|
||||||
return self.queryValue(from, selectClause, queryClauses)
|
return self.queryValue(from, selectClause, queryClauses)
|
||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
public func queryValue<T: DynamicObject, U: QueryableAttributeType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: [QueryClause]) -> U? {
|
public func queryValue<T, U: QueryableAttributeType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: [QueryClause]) -> U? {
|
||||||
|
|
||||||
let fetchRequest = CoreStoreFetchRequest()
|
let fetchRequest = CoreStoreFetchRequest()
|
||||||
let storeFound = from.applyToFetchRequest(fetchRequest, context: self)
|
let storeFound = from.applyToFetchRequest(fetchRequest, context: self)
|
||||||
@@ -269,13 +269,13 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
public func queryAttributes<T: DynamicObject>(_ from: From<T>, _ selectClause: Select<NSDictionary>, _ queryClauses: QueryClause...) -> [[String: Any]]? {
|
public func queryAttributes<T>(_ from: From<T>, _ selectClause: Select<NSDictionary>, _ queryClauses: QueryClause...) -> [[String: Any]]? {
|
||||||
|
|
||||||
return self.queryAttributes(from, selectClause, queryClauses)
|
return self.queryAttributes(from, selectClause, queryClauses)
|
||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
public func queryAttributes<T: DynamicObject>(_ from: From<T>, _ selectClause: Select<NSDictionary>, _ queryClauses: [QueryClause]) -> [[String: Any]]? {
|
public func queryAttributes<T>(_ from: From<T>, _ selectClause: Select<NSDictionary>, _ queryClauses: [QueryClause]) -> [[String: Any]]? {
|
||||||
|
|
||||||
let fetchRequest = CoreStoreFetchRequest()
|
let fetchRequest = CoreStoreFetchRequest()
|
||||||
let storeFound = from.applyToFetchRequest(fetchRequest, context: self)
|
let storeFound = from.applyToFetchRequest(fetchRequest, context: self)
|
||||||
@@ -305,13 +305,13 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource {
|
|||||||
// MARK: Deleting
|
// MARK: Deleting
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
internal func deleteAll<T: DynamicObject>(_ from: From<T>, _ deleteClauses: DeleteClause...) -> Int? {
|
internal func deleteAll<T>(_ from: From<T>, _ deleteClauses: DeleteClause...) -> Int? {
|
||||||
|
|
||||||
return self.deleteAll(from, deleteClauses)
|
return self.deleteAll(from, deleteClauses)
|
||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
internal func deleteAll<T: DynamicObject>(_ from: From<T>, _ deleteClauses: [DeleteClause]) -> Int? {
|
internal func deleteAll<T>(_ from: From<T>, _ deleteClauses: [DeleteClause]) -> Int? {
|
||||||
|
|
||||||
let fetchRequest = CoreStoreFetchRequest()
|
let fetchRequest = CoreStoreFetchRequest()
|
||||||
let storeFound = from.applyToFetchRequest(fetchRequest, context: self)
|
let storeFound = from.applyToFetchRequest(fetchRequest, context: self)
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ public final class ObjectMonitor<D: DynamicObject>: Equatable {
|
|||||||
return lhs === rhs
|
return lhs === rhs
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func == <T: DynamicObject, U: NSManagedObject>(lhs: ObjectMonitor<T>, rhs: ObjectMonitor<U>) -> Bool {
|
public static func == <T, U>(lhs: ObjectMonitor<T>, rhs: ObjectMonitor<U>) -> Bool {
|
||||||
|
|
||||||
return lhs.fetchedResultsController === rhs.fetchedResultsController
|
return lhs.fetchedResultsController === rhs.fetchedResultsController
|
||||||
}
|
}
|
||||||
@@ -142,7 +142,7 @@ public final class ObjectMonitor<D: DynamicObject>: Equatable {
|
|||||||
return lhs === rhs
|
return lhs === rhs
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func ~= <T: DynamicObject, U: DynamicObject>(lhs: ObjectMonitor<T>, rhs: ObjectMonitor<U>) -> Bool {
|
public static func ~= <T, U>(lhs: ObjectMonitor<T>, rhs: ObjectMonitor<U>) -> Bool {
|
||||||
|
|
||||||
return lhs.fetchedResultsController === rhs.fetchedResultsController
|
return lhs.fetchedResultsController === rhs.fetchedResultsController
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ public protocol ObjectObserver: class {
|
|||||||
- parameter object: the `DynamicObject` instance being observed
|
- parameter object: the `DynamicObject` instance being observed
|
||||||
- parameter changedPersistentKeys: a `Set` of key paths for the attributes that were changed. Note that `changedPersistentKeys` only contains keys for attributes/relationships present in the persistent store, thus transient properties will not be reported.
|
- parameter changedPersistentKeys: a `Set` of key paths for the attributes that were changed. Note that `changedPersistentKeys` only contains keys for attributes/relationships present in the persistent store, thus transient properties will not be reported.
|
||||||
*/
|
*/
|
||||||
func objectMonitor(_ monitor: ObjectMonitor<ObjectEntityType>, didUpdateObject object: ObjectEntityType, changedPersistentKeys: Set<KeyPath>)
|
func objectMonitor(_ monitor: ObjectMonitor<ObjectEntityType>, didUpdateObject object: ObjectEntityType, changedPersistentKeys: Set<RawKeyPath>)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Handles processing right after `object` is deleted. (Optional)
|
Handles processing right after `object` is deleted. (Optional)
|
||||||
@@ -81,7 +81,7 @@ public extension ObjectObserver {
|
|||||||
|
|
||||||
public func objectMonitor(_ monitor: ObjectMonitor<ObjectEntityType>, willUpdateObject object: ObjectEntityType) { }
|
public func objectMonitor(_ monitor: ObjectMonitor<ObjectEntityType>, willUpdateObject object: ObjectEntityType) { }
|
||||||
|
|
||||||
public func objectMonitor(_ monitor: ObjectMonitor<ObjectEntityType>, didUpdateObject object: ObjectEntityType, changedPersistentKeys: Set<KeyPath>) { }
|
public func objectMonitor(_ monitor: ObjectMonitor<ObjectEntityType>, didUpdateObject object: ObjectEntityType, changedPersistentKeys: Set<RawKeyPath>) { }
|
||||||
|
|
||||||
public func objectMonitor(_ monitor: ObjectMonitor<ObjectEntityType>, didDeleteObject object: ObjectEntityType) { }
|
public func objectMonitor(_ monitor: ObjectMonitor<ObjectEntityType>, didDeleteObject object: ObjectEntityType) { }
|
||||||
}
|
}
|
||||||
|
|||||||
+23
-7
@@ -27,9 +27,9 @@ import Foundation
|
|||||||
import CoreData
|
import CoreData
|
||||||
|
|
||||||
|
|
||||||
// MARK: - KeyPath
|
// MARK: - RawKeyPath
|
||||||
|
|
||||||
public typealias KeyPath = String
|
public typealias RawKeyPath = String
|
||||||
|
|
||||||
|
|
||||||
// MARK: - SortKey
|
// MARK: - SortKey
|
||||||
@@ -40,14 +40,24 @@ public typealias KeyPath = String
|
|||||||
public enum SortKey {
|
public enum SortKey {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Indicates that the `KeyPath` should be sorted in ascending order
|
Indicates that the `RawKeyPath` should be sorted in ascending order
|
||||||
*/
|
*/
|
||||||
case ascending(KeyPath)
|
case ascending(RawKeyPath)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Indicates that the `KeyPath` should be sorted in descending order
|
Indicates that the `RawKeyPath` should be sorted in descending order
|
||||||
*/
|
*/
|
||||||
case descending(KeyPath)
|
case descending(RawKeyPath)
|
||||||
|
|
||||||
|
/**
|
||||||
|
Indicates that the `RawKeyPath` should be sorted in ascending order in a case-insenstive manner
|
||||||
|
*/
|
||||||
|
case ascendingInsensitive(RawKeyPath)
|
||||||
|
|
||||||
|
/**
|
||||||
|
Indicates that the `RawKeyPath` should be sorted in descending order in a case-insenstive manner
|
||||||
|
*/
|
||||||
|
case descendingInsensitive(RawKeyPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -124,6 +134,12 @@ public struct OrderBy: FetchClause, QueryClause, DeleteClause, Hashable {
|
|||||||
|
|
||||||
case .descending(let keyPath):
|
case .descending(let keyPath):
|
||||||
return NSSortDescriptor(key: keyPath, ascending: false)
|
return NSSortDescriptor(key: keyPath, ascending: false)
|
||||||
|
|
||||||
|
case .ascendingInsensitive(let keyPath):
|
||||||
|
return NSSortDescriptor(key: keyPath, ascending: true, selector: #selector(NSString.localizedCaseInsensitiveCompare(_:)))
|
||||||
|
|
||||||
|
case .descendingInsensitive(let keyPath):
|
||||||
|
return NSSortDescriptor(key: keyPath, ascending: false, selector: #selector(NSString.localizedCaseInsensitiveCompare(_:)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -143,7 +159,7 @@ public struct OrderBy: FetchClause, QueryClause, DeleteClause, Hashable {
|
|||||||
|
|
||||||
// MARK: FetchClause, QueryClause, DeleteClause
|
// MARK: FetchClause, QueryClause, DeleteClause
|
||||||
|
|
||||||
public func applyToFetchRequest<ResultType: NSFetchRequestResult>(_ fetchRequest: NSFetchRequest<ResultType>) {
|
public func applyToFetchRequest<ResultType>(_ fetchRequest: NSFetchRequest<ResultType>) {
|
||||||
|
|
||||||
if let sortDescriptors = fetchRequest.sortDescriptors, sortDescriptors != self.sortDescriptors {
|
if let sortDescriptors = fetchRequest.sortDescriptors, sortDescriptors != self.sortDescriptors {
|
||||||
|
|
||||||
|
|||||||
+95
-28
@@ -34,6 +34,9 @@ import Foundation
|
|||||||
*/
|
*/
|
||||||
public struct PartialObject<O: CoreStoreObject> {
|
public struct PartialObject<O: CoreStoreObject> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns a the actual `CoreStoreObject` instance for the receiver.
|
||||||
|
*/
|
||||||
public func completeObject() -> O {
|
public func completeObject() -> O {
|
||||||
|
|
||||||
return O.cs_fromRaw(object: self.rawObject)
|
return O.cs_fromRaw(object: self.rawObject)
|
||||||
@@ -42,32 +45,48 @@ public struct PartialObject<O: CoreStoreObject> {
|
|||||||
|
|
||||||
// MARK: Value.Required accessors/mutators
|
// MARK: Value.Required accessors/mutators
|
||||||
|
|
||||||
public func value<V: ImportableAttributeType>(for property: (O) -> ValueContainer<O>.Required<V>) -> V {
|
/**
|
||||||
|
Returns the value for the property identified by a given key.
|
||||||
|
*/
|
||||||
|
public func value<V>(for property: (O) -> ValueContainer<O>.Required<V>) -> V {
|
||||||
|
|
||||||
return V.cs_fromImportableNativeType(
|
return V.cs_fromQueryableNativeType(
|
||||||
self.rawObject.value(forKey: property(O.meta).keyPath)! as! V.ImportableNativeType
|
self.rawObject.value(forKey: property(O.meta).keyPath)! as! V.QueryableNativeType
|
||||||
)!
|
)!
|
||||||
}
|
}
|
||||||
|
|
||||||
public func setValue<V: ImportableAttributeType>(_ value: V, for property: (O) -> ValueContainer<O>.Required<V>) {
|
/**
|
||||||
|
Sets the property of the receiver specified by a given key to a given value.
|
||||||
|
*/
|
||||||
|
public func setValue<V>(_ value: V, for property: (O) -> ValueContainer<O>.Required<V>) {
|
||||||
|
|
||||||
self.rawObject.setValue(
|
self.rawObject.setValue(
|
||||||
value.cs_toImportableNativeType(),
|
value.cs_toQueryableNativeType(),
|
||||||
forKey: property(O.meta).keyPath
|
forKey: property(O.meta).keyPath
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func primitiveValue<V: ImportableAttributeType>(for property: (O) -> ValueContainer<O>.Required<V>) -> V {
|
/**
|
||||||
|
Returns the value for the specified property from the managed object’s private internal storage.
|
||||||
|
|
||||||
return V.cs_fromImportableNativeType(
|
This method does not invoke the access notification methods (`willAccessValue(forKey:)` and `didAccessValue(forKey:)`). This method is used primarily by subclasses that implement custom accessor methods that need direct access to the receiver’s private storage.
|
||||||
self.rawObject.primitiveValue(forKey: property(O.meta).keyPath)! as! V.ImportableNativeType
|
*/
|
||||||
|
public func primitiveValue<V>(for property: (O) -> ValueContainer<O>.Required<V>) -> V {
|
||||||
|
|
||||||
|
return V.cs_fromQueryableNativeType(
|
||||||
|
self.rawObject.primitiveValue(forKey: property(O.meta).keyPath)! as! V.QueryableNativeType
|
||||||
)!
|
)!
|
||||||
}
|
}
|
||||||
|
|
||||||
public func setPrimitiveValue<V: ImportableAttributeType>(_ value: V, for property: (O) -> ValueContainer<O>.Required<V>) {
|
/**
|
||||||
|
Sets in the object's private internal storage the value of a given property.
|
||||||
|
|
||||||
|
Sets in the receiver’s private internal storage the value of the property specified by key to value.
|
||||||
|
*/
|
||||||
|
public func setPrimitiveValue<V>(_ value: V, for property: (O) -> ValueContainer<O>.Required<V>) {
|
||||||
|
|
||||||
self.rawObject.setPrimitiveValue(
|
self.rawObject.setPrimitiveValue(
|
||||||
value.cs_toImportableNativeType(),
|
value.cs_toQueryableNativeType(),
|
||||||
forKey: property(O.meta).keyPath
|
forKey: property(O.meta).keyPath
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -75,30 +94,46 @@ public struct PartialObject<O: CoreStoreObject> {
|
|||||||
|
|
||||||
// MARK: Value.Optional utilities
|
// MARK: Value.Optional utilities
|
||||||
|
|
||||||
public func value<V: ImportableAttributeType>(for property: (O) -> ValueContainer<O>.Optional<V>) -> V? {
|
/**
|
||||||
|
Returns the value for the property identified by a given key.
|
||||||
|
*/
|
||||||
|
public func value<V>(for property: (O) -> ValueContainer<O>.Optional<V>) -> V? {
|
||||||
|
|
||||||
return (self.rawObject.value(forKey: property(O.meta).keyPath) as! V.ImportableNativeType?)
|
return (self.rawObject.value(forKey: property(O.meta).keyPath) as! V.QueryableNativeType?)
|
||||||
.flatMap(V.cs_fromImportableNativeType)
|
.flatMap(V.cs_fromQueryableNativeType)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func setValue<V: ImportableAttributeType>(_ value: V?, for property: (O) -> ValueContainer<O>.Optional<V>) {
|
/**
|
||||||
|
Sets the property of the receiver specified by a given key to a given value.
|
||||||
|
*/
|
||||||
|
public func setValue<V>(_ value: V?, for property: (O) -> ValueContainer<O>.Optional<V>) {
|
||||||
|
|
||||||
self.rawObject.setValue(
|
self.rawObject.setValue(
|
||||||
value?.cs_toImportableNativeType(),
|
value?.cs_toQueryableNativeType(),
|
||||||
forKey: property(O.meta).keyPath
|
forKey: property(O.meta).keyPath
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func primitiveValue<V: ImportableAttributeType>(for property: (O) -> ValueContainer<O>.Optional<V>) -> V? {
|
/**
|
||||||
|
Returns the value for the specified property from the managed object’s private internal storage.
|
||||||
|
|
||||||
return (self.rawObject.primitiveValue(forKey: property(O.meta).keyPath) as! V.ImportableNativeType?)
|
This method does not invoke the access notification methods (`willAccessValue(forKey:)` and `didAccessValue(forKey:)`). This method is used primarily by subclasses that implement custom accessor methods that need direct access to the receiver’s private storage.
|
||||||
.flatMap(V.cs_fromImportableNativeType)
|
*/
|
||||||
|
public func primitiveValue<V>(for property: (O) -> ValueContainer<O>.Optional<V>) -> V? {
|
||||||
|
|
||||||
|
return (self.rawObject.primitiveValue(forKey: property(O.meta).keyPath) as! V.QueryableNativeType?)
|
||||||
|
.flatMap(V.cs_fromQueryableNativeType)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func setPrimitiveValue<V: ImportableAttributeType>(_ value: V?, for property: (O) -> ValueContainer<O>.Optional<V>) {
|
/**
|
||||||
|
Sets in the object's private internal storage the value of a given property.
|
||||||
|
|
||||||
|
Sets in the receiver’s private internal storage the value of the property specified by key to value.
|
||||||
|
*/
|
||||||
|
public func setPrimitiveValue<V>(_ value: V?, for property: (O) -> ValueContainer<O>.Optional<V>) {
|
||||||
|
|
||||||
self.rawObject.setPrimitiveValue(
|
self.rawObject.setPrimitiveValue(
|
||||||
value?.cs_toImportableNativeType(),
|
value?.cs_toQueryableNativeType(),
|
||||||
forKey: property(O.meta).keyPath
|
forKey: property(O.meta).keyPath
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -106,12 +141,18 @@ public struct PartialObject<O: CoreStoreObject> {
|
|||||||
|
|
||||||
// MARK: Transformable.Required utilities
|
// MARK: Transformable.Required utilities
|
||||||
|
|
||||||
public func value<V: NSCoding & NSCopying>(for property: (O) -> TransformableContainer<O>.Required<V>) -> V {
|
/**
|
||||||
|
Returns the value for the property identified by a given key.
|
||||||
|
*/
|
||||||
|
public func value<V>(for property: (O) -> TransformableContainer<O>.Required<V>) -> V {
|
||||||
|
|
||||||
return self.rawObject.value(forKey: property(O.meta).keyPath)! as! V
|
return self.rawObject.value(forKey: property(O.meta).keyPath)! as! V
|
||||||
}
|
}
|
||||||
|
|
||||||
public func setValue<V: NSCoding & NSCopying>(_ value: V, for property: (O) -> TransformableContainer<O>.Required<V>) {
|
/**
|
||||||
|
Sets the property of the receiver specified by a given key to a given value.
|
||||||
|
*/
|
||||||
|
public func setValue<V>(_ value: V, for property: (O) -> TransformableContainer<O>.Required<V>) {
|
||||||
|
|
||||||
self.rawObject.setValue(
|
self.rawObject.setValue(
|
||||||
value,
|
value,
|
||||||
@@ -119,12 +160,22 @@ public struct PartialObject<O: CoreStoreObject> {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func primitiveValue<V: NSCoding & NSCopying>(for property: (O) -> TransformableContainer<O>.Required<V>) -> V {
|
/**
|
||||||
|
Returns the value for the specified property from the managed object’s private internal storage.
|
||||||
|
|
||||||
|
This method does not invoke the access notification methods (`willAccessValue(forKey:)` and `didAccessValue(forKey:)`). This method is used primarily by subclasses that implement custom accessor methods that need direct access to the receiver’s private storage.
|
||||||
|
*/
|
||||||
|
public func primitiveValue<V>(for property: (O) -> TransformableContainer<O>.Required<V>) -> V {
|
||||||
|
|
||||||
return self.rawObject.primitiveValue(forKey: property(O.meta).keyPath)! as! V
|
return self.rawObject.primitiveValue(forKey: property(O.meta).keyPath)! as! V
|
||||||
}
|
}
|
||||||
|
|
||||||
public func setPrimitiveValue<V: NSCoding & NSCopying>(_ value: V, for property: (O) -> TransformableContainer<O>.Required<V>) {
|
/**
|
||||||
|
Sets in the object's private internal storage the value of a given property.
|
||||||
|
|
||||||
|
Sets in the receiver’s private internal storage the value of the property specified by key to value.
|
||||||
|
*/
|
||||||
|
public func setPrimitiveValue<V>(_ value: V, for property: (O) -> TransformableContainer<O>.Required<V>) {
|
||||||
|
|
||||||
self.rawObject.setPrimitiveValue(
|
self.rawObject.setPrimitiveValue(
|
||||||
value,
|
value,
|
||||||
@@ -135,12 +186,18 @@ public struct PartialObject<O: CoreStoreObject> {
|
|||||||
|
|
||||||
// MARK: Transformable.Optional utilities
|
// MARK: Transformable.Optional utilities
|
||||||
|
|
||||||
public func value<V: NSCoding & NSCopying>(for property: (O) -> TransformableContainer<O>.Optional<V>) -> V? {
|
/**
|
||||||
|
Returns the value for the property identified by a given key.
|
||||||
|
*/
|
||||||
|
public func value<V>(for property: (O) -> TransformableContainer<O>.Optional<V>) -> V? {
|
||||||
|
|
||||||
return self.rawObject.value(forKey: property(O.meta).keyPath) as! V?
|
return self.rawObject.value(forKey: property(O.meta).keyPath) as! V?
|
||||||
}
|
}
|
||||||
|
|
||||||
public func setValue<V: NSCoding & NSCopying>(_ value: V?, for property: (O) -> TransformableContainer<O>.Optional<V>) {
|
/**
|
||||||
|
Sets the property of the receiver specified by a given key to a given value.
|
||||||
|
*/
|
||||||
|
public func setValue<V>(_ value: V?, for property: (O) -> TransformableContainer<O>.Optional<V>) {
|
||||||
|
|
||||||
self.rawObject.setValue(
|
self.rawObject.setValue(
|
||||||
value,
|
value,
|
||||||
@@ -148,12 +205,22 @@ public struct PartialObject<O: CoreStoreObject> {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func primitiveValue<V: NSCoding & NSCopying>(for property: (O) -> TransformableContainer<O>.Optional<V>) -> V? {
|
/**
|
||||||
|
Returns the value for the specified property from the managed object’s private internal storage.
|
||||||
|
|
||||||
|
This method does not invoke the access notification methods (`willAccessValue(forKey:)` and `didAccessValue(forKey:)`). This method is used primarily by subclasses that implement custom accessor methods that need direct access to the receiver’s private storage.
|
||||||
|
*/
|
||||||
|
public func primitiveValue<V>(for property: (O) -> TransformableContainer<O>.Optional<V>) -> V? {
|
||||||
|
|
||||||
return self.rawObject.primitiveValue(forKey: property(O.meta).keyPath) as! V?
|
return self.rawObject.primitiveValue(forKey: property(O.meta).keyPath) as! V?
|
||||||
}
|
}
|
||||||
|
|
||||||
public func setPrimitiveValue<V: NSCoding & NSCopying>(_ value: V?, for property: (O) -> TransformableContainer<O>.Optional<V>) {
|
/**
|
||||||
|
Sets in the object's private internal storage the value of a given property.
|
||||||
|
|
||||||
|
Sets in the receiver’s private internal storage the value of the property specified by key to value.
|
||||||
|
*/
|
||||||
|
public func setPrimitiveValue<V>(_ value: V?, for property: (O) -> TransformableContainer<O>.Optional<V>) {
|
||||||
|
|
||||||
self.rawObject.setPrimitiveValue(
|
self.rawObject.setPrimitiveValue(
|
||||||
value,
|
value,
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ public protocol QueryableAttributeType: Hashable, SelectResultType {
|
|||||||
/**
|
/**
|
||||||
The `CoreDataNativeType` for this type when used in `Select` clauses.
|
The `CoreDataNativeType` for this type when used in `Select` clauses.
|
||||||
*/
|
*/
|
||||||
associatedtype QueryableNativeType: CoreDataNativeType
|
associatedtype QueryableNativeType
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The `NSAttributeType` for this type when used in `Select` clauses.
|
The `NSAttributeType` for this type when used in `Select` clauses.
|
||||||
@@ -111,7 +111,7 @@ extension Bool: QueryableAttributeType {
|
|||||||
@inline(__always)
|
@inline(__always)
|
||||||
public func cs_toQueryableNativeType() -> QueryableNativeType {
|
public func cs_toQueryableNativeType() -> QueryableNativeType {
|
||||||
|
|
||||||
return self as NSNumber
|
return self as QueryableNativeType
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,7 +133,7 @@ extension CGFloat: QueryableAttributeType {
|
|||||||
@inline(__always)
|
@inline(__always)
|
||||||
public func cs_toQueryableNativeType() -> QueryableNativeType {
|
public func cs_toQueryableNativeType() -> QueryableNativeType {
|
||||||
|
|
||||||
return self as NSNumber
|
return self as QueryableNativeType
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,7 +155,7 @@ extension Data: QueryableAttributeType {
|
|||||||
@inline(__always)
|
@inline(__always)
|
||||||
public func cs_toQueryableNativeType() -> QueryableNativeType {
|
public func cs_toQueryableNativeType() -> QueryableNativeType {
|
||||||
|
|
||||||
return self as NSData
|
return self as QueryableNativeType
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -342,7 +342,10 @@ extension NSData: QueryableAttributeType {
|
|||||||
|
|
||||||
public typealias QueryableNativeType = NSData
|
public typealias QueryableNativeType = NSData
|
||||||
|
|
||||||
public static let cs_rawAttributeType: NSAttributeType = .binaryDataAttributeType
|
public class var cs_rawAttributeType: NSAttributeType {
|
||||||
|
|
||||||
|
return .binaryDataAttributeType
|
||||||
|
}
|
||||||
|
|
||||||
@nonobjc @inline(__always)
|
@nonobjc @inline(__always)
|
||||||
public class func cs_fromQueryableNativeType(_ value: QueryableNativeType) -> Self? {
|
public class func cs_fromQueryableNativeType(_ value: QueryableNativeType) -> Self? {
|
||||||
@@ -369,7 +372,10 @@ extension NSDate: QueryableAttributeType {
|
|||||||
|
|
||||||
public typealias QueryableNativeType = NSDate
|
public typealias QueryableNativeType = NSDate
|
||||||
|
|
||||||
public static let cs_rawAttributeType: NSAttributeType = .dateAttributeType
|
public class var cs_rawAttributeType: NSAttributeType {
|
||||||
|
|
||||||
|
return .dateAttributeType
|
||||||
|
}
|
||||||
|
|
||||||
@nonobjc @inline(__always)
|
@nonobjc @inline(__always)
|
||||||
public class func cs_fromQueryableNativeType(_ value: QueryableNativeType) -> Self? {
|
public class func cs_fromQueryableNativeType(_ value: QueryableNativeType) -> Self? {
|
||||||
@@ -407,7 +413,10 @@ extension NSManagedObjectID: QueryableAttributeType {
|
|||||||
|
|
||||||
public typealias QueryableNativeType = NSManagedObjectID
|
public typealias QueryableNativeType = NSManagedObjectID
|
||||||
|
|
||||||
public static let cs_rawAttributeType: NSAttributeType = .objectIDAttributeType
|
public class var cs_rawAttributeType: NSAttributeType {
|
||||||
|
|
||||||
|
return .objectIDAttributeType
|
||||||
|
}
|
||||||
|
|
||||||
@nonobjc @inline(__always)
|
@nonobjc @inline(__always)
|
||||||
public class func cs_fromQueryableNativeType(_ value: QueryableNativeType) -> Self? {
|
public class func cs_fromQueryableNativeType(_ value: QueryableNativeType) -> Self? {
|
||||||
@@ -434,12 +443,20 @@ extension NSNull: QueryableAttributeType {
|
|||||||
|
|
||||||
public typealias QueryableNativeType = NSNull
|
public typealias QueryableNativeType = NSNull
|
||||||
|
|
||||||
public static let cs_rawAttributeType: NSAttributeType = .undefinedAttributeType
|
public class var cs_rawAttributeType: NSAttributeType {
|
||||||
|
|
||||||
|
return .undefinedAttributeType
|
||||||
|
}
|
||||||
|
|
||||||
@nonobjc @inline(__always)
|
@nonobjc @inline(__always)
|
||||||
public static func cs_fromQueryableNativeType(_ value: QueryableNativeType) -> Self? {
|
public class func cs_fromQueryableNativeType(_ value: QueryableNativeType) -> Self? {
|
||||||
|
|
||||||
return self.init()
|
@inline(__always)
|
||||||
|
func forceCast<T: NSNull>(_ value: Any) -> T? {
|
||||||
|
|
||||||
|
return value as? T
|
||||||
|
}
|
||||||
|
return forceCast(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc @inline(__always)
|
@nonobjc @inline(__always)
|
||||||
@@ -486,7 +503,10 @@ extension NSString: QueryableAttributeType {
|
|||||||
|
|
||||||
public typealias QueryableNativeType = NSString
|
public typealias QueryableNativeType = NSString
|
||||||
|
|
||||||
public static let cs_rawAttributeType: NSAttributeType = .stringAttributeType
|
public class var cs_rawAttributeType: NSAttributeType {
|
||||||
|
|
||||||
|
return .stringAttributeType
|
||||||
|
}
|
||||||
|
|
||||||
@nonobjc @inline(__always)
|
@nonobjc @inline(__always)
|
||||||
public class func cs_fromQueryableNativeType(_ value: QueryableNativeType) -> Self? {
|
public class func cs_fromQueryableNativeType(_ value: QueryableNativeType) -> Self? {
|
||||||
@@ -513,10 +533,13 @@ extension NSURL: QueryableAttributeType {
|
|||||||
|
|
||||||
public typealias QueryableNativeType = NSString
|
public typealias QueryableNativeType = NSString
|
||||||
|
|
||||||
public static let cs_rawAttributeType: NSAttributeType = .stringAttributeType
|
public class var cs_rawAttributeType: NSAttributeType {
|
||||||
|
|
||||||
|
return .stringAttributeType
|
||||||
|
}
|
||||||
|
|
||||||
@nonobjc @inline(__always)
|
@nonobjc @inline(__always)
|
||||||
public static func cs_fromQueryableNativeType(_ value: QueryableNativeType) -> Self? {
|
public class func cs_fromQueryableNativeType(_ value: QueryableNativeType) -> Self? {
|
||||||
|
|
||||||
return self.init(string: value as String)
|
return self.init(string: value as String)
|
||||||
}
|
}
|
||||||
@@ -535,10 +558,13 @@ extension NSUUID: QueryableAttributeType {
|
|||||||
|
|
||||||
public typealias QueryableNativeType = NSString
|
public typealias QueryableNativeType = NSString
|
||||||
|
|
||||||
public static let cs_rawAttributeType: NSAttributeType = .stringAttributeType
|
public class var cs_rawAttributeType: NSAttributeType {
|
||||||
|
|
||||||
|
return .stringAttributeType
|
||||||
|
}
|
||||||
|
|
||||||
@nonobjc @inline(__always)
|
@nonobjc @inline(__always)
|
||||||
public static func cs_fromQueryableNativeType(_ value: QueryableNativeType) -> Self? {
|
public class func cs_fromQueryableNativeType(_ value: QueryableNativeType) -> Self? {
|
||||||
|
|
||||||
return self.init(uuidString: value.lowercased)
|
return self.init(uuidString: value.lowercased)
|
||||||
}
|
}
|
||||||
@@ -568,7 +594,7 @@ extension String: QueryableAttributeType {
|
|||||||
@inline(__always)
|
@inline(__always)
|
||||||
public func cs_toQueryableNativeType() -> QueryableNativeType {
|
public func cs_toQueryableNativeType() -> QueryableNativeType {
|
||||||
|
|
||||||
return self as NSString
|
return self as QueryableNativeType
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ public protocol QueryableSource: class {
|
|||||||
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
||||||
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
||||||
*/
|
*/
|
||||||
func queryValue<T: DynamicObject, U: QueryableAttributeType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: QueryClause...) -> U?
|
func queryValue<T, U: QueryableAttributeType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: QueryClause...) -> U?
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Queries aggregate values as specified by the `QueryClause`s. Requires at least a `Select` clause, and optional `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
Queries aggregate values as specified by the `QueryClause`s. Requires at least a `Select` clause, and optional `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
||||||
@@ -56,7 +56,7 @@ public protocol QueryableSource: class {
|
|||||||
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
||||||
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
||||||
*/
|
*/
|
||||||
func queryValue<T: DynamicObject, U: QueryableAttributeType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: [QueryClause]) -> U?
|
func queryValue<T, U: QueryableAttributeType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: [QueryClause]) -> U?
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Queries a dictionary of attribute values as specified by the `QueryClause`s. Requires at least a `Select` clause, and optional `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
Queries a dictionary of attribute values as specified by the `QueryClause`s. Requires at least a `Select` clause, and optional `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
||||||
@@ -68,7 +68,7 @@ public protocol QueryableSource: class {
|
|||||||
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
||||||
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
||||||
*/
|
*/
|
||||||
func queryAttributes<T: DynamicObject>(_ from: From<T>, _ selectClause: Select<NSDictionary>, _ queryClauses: QueryClause...) -> [[String: Any]]?
|
func queryAttributes<T>(_ from: From<T>, _ selectClause: Select<NSDictionary>, _ queryClauses: QueryClause...) -> [[String: Any]]?
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Queries a dictionary of attribute values as specified by the `QueryClause`s. Requires at least a `Select` clause, and optional `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
Queries a dictionary of attribute values as specified by the `QueryClause`s. Requires at least a `Select` clause, and optional `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
||||||
@@ -80,7 +80,7 @@ public protocol QueryableSource: class {
|
|||||||
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
||||||
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
||||||
*/
|
*/
|
||||||
func queryAttributes<T: DynamicObject>(_ from: From<T>, _ selectClause: Select<NSDictionary>, _ queryClauses: [QueryClause]) -> [[String: Any]]?
|
func queryAttributes<T>(_ from: From<T>, _ selectClause: Select<NSDictionary>, _ queryClauses: [QueryClause]) -> [[String: Any]]?
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The internal `NSManagedObjectContext` managed by this `QueryableSource`. Using this context directly should typically be avoided, and is provided by CoreStore only for extremely specialized cases.
|
The internal `NSManagedObjectContext` managed by this `QueryableSource`. Using this context directly should typically be avoided, and is provided by CoreStore only for extremely specialized cases.
|
||||||
|
|||||||
+29
-29
@@ -95,7 +95,7 @@ public enum RelationshipContainer<O: CoreStoreObject> {
|
|||||||
- parameter affectedByKeyPaths: a set of key paths for properties whose values affect the value of the receiver. This is similar to `NSManagedObject.keyPathsForValuesAffectingValue(forKey:)`.
|
- parameter affectedByKeyPaths: a set of key paths for properties whose values affect the value of the receiver. This is similar to `NSManagedObject.keyPathsForValuesAffectingValue(forKey:)`.
|
||||||
*/
|
*/
|
||||||
public convenience init(
|
public convenience init(
|
||||||
_ keyPath: KeyPath,
|
_ keyPath: RawKeyPath,
|
||||||
deleteRule: DeleteRule = .nullify,
|
deleteRule: DeleteRule = .nullify,
|
||||||
versionHashModifier: @autoclosure @escaping () -> String? = nil,
|
versionHashModifier: @autoclosure @escaping () -> String? = nil,
|
||||||
renamingIdentifier: @autoclosure @escaping () -> String? = nil,
|
renamingIdentifier: @autoclosure @escaping () -> String? = nil,
|
||||||
@@ -129,7 +129,7 @@ public enum RelationshipContainer<O: CoreStoreObject> {
|
|||||||
- parameter affectedByKeyPaths: a set of key paths for properties whose values affect the value of the receiver. This is similar to `NSManagedObject.keyPathsForValuesAffectingValue(forKey:)`.
|
- parameter affectedByKeyPaths: a set of key paths for properties whose values affect the value of the receiver. This is similar to `NSManagedObject.keyPathsForValuesAffectingValue(forKey:)`.
|
||||||
*/
|
*/
|
||||||
public convenience init(
|
public convenience init(
|
||||||
_ keyPath: KeyPath,
|
_ keyPath: RawKeyPath,
|
||||||
inverse: @escaping (D) -> RelationshipContainer<D>.ToOne<O>,
|
inverse: @escaping (D) -> RelationshipContainer<D>.ToOne<O>,
|
||||||
deleteRule: DeleteRule = .nullify,
|
deleteRule: DeleteRule = .nullify,
|
||||||
versionHashModifier: @autoclosure @escaping () -> String? = nil,
|
versionHashModifier: @autoclosure @escaping () -> String? = nil,
|
||||||
@@ -164,7 +164,7 @@ public enum RelationshipContainer<O: CoreStoreObject> {
|
|||||||
- parameter affectedByKeyPaths: a set of key paths for properties whose values affect the value of the receiver. This is similar to `NSManagedObject.keyPathsForValuesAffectingValue(forKey:)`.
|
- parameter affectedByKeyPaths: a set of key paths for properties whose values affect the value of the receiver. This is similar to `NSManagedObject.keyPathsForValuesAffectingValue(forKey:)`.
|
||||||
*/
|
*/
|
||||||
public convenience init(
|
public convenience init(
|
||||||
_ keyPath: KeyPath,
|
_ keyPath: RawKeyPath,
|
||||||
inverse: @escaping (D) -> RelationshipContainer<D>.ToManyOrdered<O>,
|
inverse: @escaping (D) -> RelationshipContainer<D>.ToManyOrdered<O>,
|
||||||
deleteRule: DeleteRule = .nullify,
|
deleteRule: DeleteRule = .nullify,
|
||||||
versionHashModifier: @autoclosure @escaping () -> String? = nil,
|
versionHashModifier: @autoclosure @escaping () -> String? = nil,
|
||||||
@@ -199,7 +199,7 @@ public enum RelationshipContainer<O: CoreStoreObject> {
|
|||||||
- parameter affectedByKeyPaths: a set of key paths for properties whose values affect the value of the receiver. This is similar to `NSManagedObject.keyPathsForValuesAffectingValue(forKey:)`.
|
- parameter affectedByKeyPaths: a set of key paths for properties whose values affect the value of the receiver. This is similar to `NSManagedObject.keyPathsForValuesAffectingValue(forKey:)`.
|
||||||
*/
|
*/
|
||||||
public convenience init(
|
public convenience init(
|
||||||
_ keyPath: KeyPath,
|
_ keyPath: RawKeyPath,
|
||||||
inverse: @escaping (D) -> RelationshipContainer<D>.ToManyUnordered<O>,
|
inverse: @escaping (D) -> RelationshipContainer<D>.ToManyUnordered<O>,
|
||||||
deleteRule: DeleteRule = .nullify,
|
deleteRule: DeleteRule = .nullify,
|
||||||
versionHashModifier: @autoclosure @escaping () -> String? = nil,
|
versionHashModifier: @autoclosure @escaping () -> String? = nil,
|
||||||
@@ -234,14 +234,14 @@ public enum RelationshipContainer<O: CoreStoreObject> {
|
|||||||
|
|
||||||
// MARK: RelationshipProtocol
|
// MARK: RelationshipProtocol
|
||||||
|
|
||||||
public let keyPath: KeyPath
|
public let keyPath: RawKeyPath
|
||||||
|
|
||||||
internal let isToMany = false
|
internal let isToMany = false
|
||||||
internal let isOrdered = false
|
internal let isOrdered = false
|
||||||
internal let deleteRule: NSDeleteRule
|
internal let deleteRule: NSDeleteRule
|
||||||
internal let minCount: Int = 0
|
internal let minCount: Int = 0
|
||||||
internal let maxCount: Int = 1
|
internal let maxCount: Int = 1
|
||||||
internal let inverse: (type: CoreStoreObject.Type, keyPath: () -> KeyPath?)
|
internal let inverse: (type: CoreStoreObject.Type, keyPath: () -> RawKeyPath?)
|
||||||
internal let versionHashModifier: () -> String?
|
internal let versionHashModifier: () -> String?
|
||||||
internal let renamingIdentifier: () -> String?
|
internal let renamingIdentifier: () -> String?
|
||||||
internal let affectedByKeyPaths: () -> Set<String>
|
internal let affectedByKeyPaths: () -> Set<String>
|
||||||
@@ -294,7 +294,7 @@ public enum RelationshipContainer<O: CoreStoreObject> {
|
|||||||
|
|
||||||
// MARK: Private
|
// MARK: Private
|
||||||
|
|
||||||
private init(keyPath: KeyPath, inverseKeyPath: @escaping () -> KeyPath?, deleteRule: DeleteRule, versionHashModifier: @autoclosure @escaping () -> String?, renamingIdentifier: @autoclosure @escaping () -> String?, affectedByKeyPaths: @autoclosure @escaping () -> Set<String>) {
|
private init(keyPath: RawKeyPath, inverseKeyPath: @escaping () -> RawKeyPath?, deleteRule: DeleteRule, versionHashModifier: @autoclosure @escaping () -> String?, renamingIdentifier: @autoclosure @escaping () -> String?, affectedByKeyPaths: @autoclosure @escaping () -> Set<String>) {
|
||||||
|
|
||||||
self.keyPath = keyPath
|
self.keyPath = keyPath
|
||||||
self.deleteRule = deleteRule.nativeValue
|
self.deleteRule = deleteRule.nativeValue
|
||||||
@@ -341,7 +341,7 @@ public enum RelationshipContainer<O: CoreStoreObject> {
|
|||||||
- parameter affectedByKeyPaths: a set of key paths for properties whose values affect the value of the receiver. This is similar to `NSManagedObject.keyPathsForValuesAffectingValue(forKey:)`.
|
- parameter affectedByKeyPaths: a set of key paths for properties whose values affect the value of the receiver. This is similar to `NSManagedObject.keyPathsForValuesAffectingValue(forKey:)`.
|
||||||
*/
|
*/
|
||||||
public convenience init(
|
public convenience init(
|
||||||
_ keyPath: KeyPath,
|
_ keyPath: RawKeyPath,
|
||||||
minCount: Int = 0,
|
minCount: Int = 0,
|
||||||
maxCount: Int = 0,
|
maxCount: Int = 0,
|
||||||
deleteRule: DeleteRule = .nullify,
|
deleteRule: DeleteRule = .nullify,
|
||||||
@@ -381,7 +381,7 @@ public enum RelationshipContainer<O: CoreStoreObject> {
|
|||||||
- parameter affectedByKeyPaths: a set of key paths for properties whose values affect the value of the receiver. This is similar to `NSManagedObject.keyPathsForValuesAffectingValue(forKey:)`.
|
- parameter affectedByKeyPaths: a set of key paths for properties whose values affect the value of the receiver. This is similar to `NSManagedObject.keyPathsForValuesAffectingValue(forKey:)`.
|
||||||
*/
|
*/
|
||||||
public convenience init(
|
public convenience init(
|
||||||
_ keyPath: KeyPath,
|
_ keyPath: RawKeyPath,
|
||||||
minCount: Int = 0,
|
minCount: Int = 0,
|
||||||
maxCount: Int = 0,
|
maxCount: Int = 0,
|
||||||
inverse: @escaping (D) -> RelationshipContainer<D>.ToOne<O>,
|
inverse: @escaping (D) -> RelationshipContainer<D>.ToOne<O>,
|
||||||
@@ -422,7 +422,7 @@ public enum RelationshipContainer<O: CoreStoreObject> {
|
|||||||
- parameter affectedByKeyPaths: a set of key paths for properties whose values affect the value of the receiver. This is similar to `NSManagedObject.keyPathsForValuesAffectingValue(forKey:)`.
|
- parameter affectedByKeyPaths: a set of key paths for properties whose values affect the value of the receiver. This is similar to `NSManagedObject.keyPathsForValuesAffectingValue(forKey:)`.
|
||||||
*/
|
*/
|
||||||
public convenience init(
|
public convenience init(
|
||||||
_ keyPath: KeyPath,
|
_ keyPath: RawKeyPath,
|
||||||
minCount: Int = 0,
|
minCount: Int = 0,
|
||||||
maxCount: Int = 0,
|
maxCount: Int = 0,
|
||||||
inverse: @escaping (D) -> RelationshipContainer<D>.ToManyOrdered<O>,
|
inverse: @escaping (D) -> RelationshipContainer<D>.ToManyOrdered<O>,
|
||||||
@@ -463,7 +463,7 @@ public enum RelationshipContainer<O: CoreStoreObject> {
|
|||||||
- parameter affectedByKeyPaths: a set of key paths for properties whose values affect the value of the receiver. This is similar to `NSManagedObject.keyPathsForValuesAffectingValue(forKey:)`.
|
- parameter affectedByKeyPaths: a set of key paths for properties whose values affect the value of the receiver. This is similar to `NSManagedObject.keyPathsForValuesAffectingValue(forKey:)`.
|
||||||
*/
|
*/
|
||||||
public convenience init(
|
public convenience init(
|
||||||
_ keyPath: KeyPath,
|
_ keyPath: RawKeyPath,
|
||||||
minCount: Int = 0,
|
minCount: Int = 0,
|
||||||
maxCount: Int = 0,
|
maxCount: Int = 0,
|
||||||
inverse: @escaping (D) -> RelationshipContainer<D>.ToManyUnordered<O>,
|
inverse: @escaping (D) -> RelationshipContainer<D>.ToManyUnordered<O>,
|
||||||
@@ -502,7 +502,7 @@ public enum RelationshipContainer<O: CoreStoreObject> {
|
|||||||
|
|
||||||
// MARK: RelationshipProtocol
|
// MARK: RelationshipProtocol
|
||||||
|
|
||||||
public let keyPath: KeyPath
|
public let keyPath: RawKeyPath
|
||||||
|
|
||||||
internal let isToMany = true
|
internal let isToMany = true
|
||||||
internal let isOptional = true
|
internal let isOptional = true
|
||||||
@@ -510,7 +510,7 @@ public enum RelationshipContainer<O: CoreStoreObject> {
|
|||||||
internal let deleteRule: NSDeleteRule
|
internal let deleteRule: NSDeleteRule
|
||||||
internal let minCount: Int
|
internal let minCount: Int
|
||||||
internal let maxCount: Int
|
internal let maxCount: Int
|
||||||
internal let inverse: (type: CoreStoreObject.Type, keyPath: () -> KeyPath?)
|
internal let inverse: (type: CoreStoreObject.Type, keyPath: () -> RawKeyPath?)
|
||||||
internal let versionHashModifier: () -> String?
|
internal let versionHashModifier: () -> String?
|
||||||
internal let renamingIdentifier: () -> String?
|
internal let renamingIdentifier: () -> String?
|
||||||
internal let affectedByKeyPaths: () -> Set<String>
|
internal let affectedByKeyPaths: () -> Set<String>
|
||||||
@@ -615,7 +615,7 @@ public enum RelationshipContainer<O: CoreStoreObject> {
|
|||||||
- parameter affectedByKeyPaths: a set of key paths for properties whose values affect the value of the receiver. This is similar to `NSManagedObject.keyPathsForValuesAffectingValue(forKey:)`.
|
- parameter affectedByKeyPaths: a set of key paths for properties whose values affect the value of the receiver. This is similar to `NSManagedObject.keyPathsForValuesAffectingValue(forKey:)`.
|
||||||
*/
|
*/
|
||||||
public convenience init(
|
public convenience init(
|
||||||
_ keyPath: KeyPath,
|
_ keyPath: RawKeyPath,
|
||||||
deleteRule: DeleteRule = .nullify,
|
deleteRule: DeleteRule = .nullify,
|
||||||
minCount: Int = 0,
|
minCount: Int = 0,
|
||||||
maxCount: Int = 0,
|
maxCount: Int = 0,
|
||||||
@@ -655,7 +655,7 @@ public enum RelationshipContainer<O: CoreStoreObject> {
|
|||||||
- parameter affectedByKeyPaths: a set of key paths for properties whose values affect the value of the receiver. This is similar to `NSManagedObject.keyPathsForValuesAffectingValue(forKey:)`.
|
- parameter affectedByKeyPaths: a set of key paths for properties whose values affect the value of the receiver. This is similar to `NSManagedObject.keyPathsForValuesAffectingValue(forKey:)`.
|
||||||
*/
|
*/
|
||||||
public convenience init(
|
public convenience init(
|
||||||
_ keyPath: KeyPath,
|
_ keyPath: RawKeyPath,
|
||||||
inverse: @escaping (D) -> RelationshipContainer<D>.ToOne<O>,
|
inverse: @escaping (D) -> RelationshipContainer<D>.ToOne<O>,
|
||||||
deleteRule: DeleteRule = .nullify,
|
deleteRule: DeleteRule = .nullify,
|
||||||
minCount: Int = 0,
|
minCount: Int = 0,
|
||||||
@@ -696,7 +696,7 @@ public enum RelationshipContainer<O: CoreStoreObject> {
|
|||||||
- parameter affectedByKeyPaths: a set of key paths for properties whose values affect the value of the receiver. This is similar to `NSManagedObject.keyPathsForValuesAffectingValue(forKey:)`.
|
- parameter affectedByKeyPaths: a set of key paths for properties whose values affect the value of the receiver. This is similar to `NSManagedObject.keyPathsForValuesAffectingValue(forKey:)`.
|
||||||
*/
|
*/
|
||||||
public convenience init(
|
public convenience init(
|
||||||
_ keyPath: KeyPath,
|
_ keyPath: RawKeyPath,
|
||||||
inverse: @escaping (D) -> RelationshipContainer<D>.ToManyOrdered<O>,
|
inverse: @escaping (D) -> RelationshipContainer<D>.ToManyOrdered<O>,
|
||||||
deleteRule: DeleteRule = .nullify,
|
deleteRule: DeleteRule = .nullify,
|
||||||
minCount: Int = 0,
|
minCount: Int = 0,
|
||||||
@@ -737,7 +737,7 @@ public enum RelationshipContainer<O: CoreStoreObject> {
|
|||||||
- parameter affectedByKeyPaths: a set of key paths for properties whose values affect the value of the receiver. This is similar to `NSManagedObject.keyPathsForValuesAffectingValue(forKey:)`.
|
- parameter affectedByKeyPaths: a set of key paths for properties whose values affect the value of the receiver. This is similar to `NSManagedObject.keyPathsForValuesAffectingValue(forKey:)`.
|
||||||
*/
|
*/
|
||||||
public convenience init(
|
public convenience init(
|
||||||
_ keyPath: KeyPath,
|
_ keyPath: RawKeyPath,
|
||||||
inverse: @escaping (D) -> RelationshipContainer<D>.ToManyUnordered<O>,
|
inverse: @escaping (D) -> RelationshipContainer<D>.ToManyUnordered<O>,
|
||||||
deleteRule: DeleteRule = .nullify,
|
deleteRule: DeleteRule = .nullify,
|
||||||
minCount: Int = 0,
|
minCount: Int = 0,
|
||||||
@@ -776,7 +776,7 @@ public enum RelationshipContainer<O: CoreStoreObject> {
|
|||||||
|
|
||||||
// MARK: RelationshipProtocol
|
// MARK: RelationshipProtocol
|
||||||
|
|
||||||
public let keyPath: KeyPath
|
public let keyPath: RawKeyPath
|
||||||
|
|
||||||
internal let isToMany = true
|
internal let isToMany = true
|
||||||
internal let isOptional = true
|
internal let isOptional = true
|
||||||
@@ -784,7 +784,7 @@ public enum RelationshipContainer<O: CoreStoreObject> {
|
|||||||
internal let deleteRule: NSDeleteRule
|
internal let deleteRule: NSDeleteRule
|
||||||
internal let minCount: Int
|
internal let minCount: Int
|
||||||
internal let maxCount: Int
|
internal let maxCount: Int
|
||||||
internal let inverse: (type: CoreStoreObject.Type, keyPath: () -> KeyPath?)
|
internal let inverse: (type: CoreStoreObject.Type, keyPath: () -> RawKeyPath?)
|
||||||
internal let versionHashModifier: () -> String?
|
internal let versionHashModifier: () -> String?
|
||||||
internal let renamingIdentifier: () -> String?
|
internal let renamingIdentifier: () -> String?
|
||||||
internal let affectedByKeyPaths: () -> Set<String>
|
internal let affectedByKeyPaths: () -> Set<String>
|
||||||
@@ -837,7 +837,7 @@ public enum RelationshipContainer<O: CoreStoreObject> {
|
|||||||
|
|
||||||
// MARK: Private
|
// MARK: Private
|
||||||
|
|
||||||
private init(keyPath: KeyPath, inverseKeyPath: @escaping () -> KeyPath?, deleteRule: DeleteRule, minCount: Int, maxCount: Int, versionHashModifier: @autoclosure @escaping () -> String?, renamingIdentifier: @autoclosure @escaping () -> String?, affectedByKeyPaths: @autoclosure @escaping () -> Set<String>) {
|
private init(keyPath: RawKeyPath, inverseKeyPath: @escaping () -> RawKeyPath?, deleteRule: DeleteRule, minCount: Int, maxCount: Int, versionHashModifier: @autoclosure @escaping () -> String?, renamingIdentifier: @autoclosure @escaping () -> String?, affectedByKeyPaths: @autoclosure @escaping () -> Set<String>) {
|
||||||
|
|
||||||
self.keyPath = keyPath
|
self.keyPath = keyPath
|
||||||
self.deleteRule = deleteRule.nativeValue
|
self.deleteRule = deleteRule.nativeValue
|
||||||
@@ -884,7 +884,7 @@ extension RelationshipContainer.ToManyOrdered: RandomAccessCollection {
|
|||||||
|
|
||||||
public func makeIterator() -> Iterator {
|
public func makeIterator() -> Iterator {
|
||||||
|
|
||||||
let iterator = self.nativeValue.makeIterator()
|
var iterator = self.nativeValue.makeIterator()
|
||||||
return AnyIterator({ iterator.next().flatMap({ D.cs_fromRaw(object: $0 as! NSManagedObject) }) })
|
return AnyIterator({ iterator.next().flatMap({ D.cs_fromRaw(object: $0 as! NSManagedObject) }) })
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -939,7 +939,7 @@ extension RelationshipContainer.ToManyUnordered: Sequence {
|
|||||||
|
|
||||||
public func makeIterator() -> Iterator {
|
public func makeIterator() -> Iterator {
|
||||||
|
|
||||||
let iterator = self.nativeValue.makeIterator()
|
var iterator = self.nativeValue.makeIterator()
|
||||||
return AnyIterator({ iterator.next().flatMap({ D.cs_fromRaw(object: $0 as! NSManagedObject) }) })
|
return AnyIterator({ iterator.next().flatMap({ D.cs_fromRaw(object: $0 as! NSManagedObject) }) })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -977,7 +977,7 @@ extension RelationshipContainer.ToOne {
|
|||||||
dog.master.value = anotherDog.master.value
|
dog.master.value = anotherDog.master.value
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
public static func .= <O2: CoreStoreObject>(_ relationship: RelationshipContainer<O>.ToOne<D>, _ relationship2: RelationshipContainer<O2>.ToOne<D>) {
|
public static func .= <O2>(_ relationship: RelationshipContainer<O>.ToOne<D>, _ relationship2: RelationshipContainer<O2>.ToOne<D>) {
|
||||||
|
|
||||||
relationship.nativeValue = relationship2.nativeValue
|
relationship.nativeValue = relationship2.nativeValue
|
||||||
}
|
}
|
||||||
@@ -1022,7 +1022,7 @@ extension RelationshipContainer.ToOne {
|
|||||||
if dog.master.value == person { ... }
|
if dog.master.value == person { ... }
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
public static func .== <O2: CoreStoreObject>(_ relationship: RelationshipContainer<O>.ToOne<D>, _ relationship2: RelationshipContainer<O2>.ToOne<D>) -> Bool {
|
public static func .== <O2>(_ relationship: RelationshipContainer<O>.ToOne<D>, _ relationship2: RelationshipContainer<O2>.ToOne<D>) -> Bool {
|
||||||
|
|
||||||
return relationship.nativeValue == relationship2.nativeValue
|
return relationship.nativeValue == relationship2.nativeValue
|
||||||
}
|
}
|
||||||
@@ -1055,7 +1055,7 @@ extension RelationshipContainer.ToManyOrdered {
|
|||||||
person.pets.value = anotherPerson.pets.value
|
person.pets.value = anotherPerson.pets.value
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
public static func .= <O2: CoreStoreObject>(_ relationship: RelationshipContainer<O>.ToManyOrdered<D>, _ relationship2: RelationshipContainer<O2>.ToManyOrdered<D>) {
|
public static func .= <O2>(_ relationship: RelationshipContainer<O>.ToManyOrdered<D>, _ relationship2: RelationshipContainer<O2>.ToManyOrdered<D>) {
|
||||||
|
|
||||||
relationship.nativeValue = relationship2.nativeValue
|
relationship.nativeValue = relationship2.nativeValue
|
||||||
}
|
}
|
||||||
@@ -1106,7 +1106,7 @@ extension RelationshipContainer.ToManyOrdered {
|
|||||||
if person.pets.value == anotherPerson.pets.value { ... }
|
if person.pets.value == anotherPerson.pets.value { ... }
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
public static func .== <O2: CoreStoreObject>(_ relationship: RelationshipContainer<O>.ToManyOrdered<D>, _ relationship2: RelationshipContainer<O2>.ToManyOrdered<D>) -> Bool {
|
public static func .== <O2>(_ relationship: RelationshipContainer<O>.ToManyOrdered<D>, _ relationship2: RelationshipContainer<O2>.ToManyOrdered<D>) -> Bool {
|
||||||
|
|
||||||
return relationship.nativeValue == relationship2.nativeValue
|
return relationship.nativeValue == relationship2.nativeValue
|
||||||
}
|
}
|
||||||
@@ -1139,7 +1139,7 @@ extension RelationshipContainer.ToManyUnordered {
|
|||||||
person.pets.value = anotherPerson.pets.value
|
person.pets.value = anotherPerson.pets.value
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
public static func .= <O2: CoreStoreObject>(_ relationship: RelationshipContainer<O>.ToManyUnordered<D>, _ relationship2: RelationshipContainer<O2>.ToManyUnordered<D>) {
|
public static func .= <O2>(_ relationship: RelationshipContainer<O>.ToManyUnordered<D>, _ relationship2: RelationshipContainer<O2>.ToManyUnordered<D>) {
|
||||||
|
|
||||||
relationship.nativeValue = relationship2.nativeValue
|
relationship.nativeValue = relationship2.nativeValue
|
||||||
}
|
}
|
||||||
@@ -1154,7 +1154,7 @@ extension RelationshipContainer.ToManyUnordered {
|
|||||||
person.pets.value = anotherPerson.pets.value
|
person.pets.value = anotherPerson.pets.value
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
public static func .= <O2: CoreStoreObject>(_ relationship: RelationshipContainer<O>.ToManyUnordered<D>, _ relationship2: RelationshipContainer<O2>.ToManyOrdered<D>) {
|
public static func .= <O2>(_ relationship: RelationshipContainer<O>.ToManyUnordered<D>, _ relationship2: RelationshipContainer<O2>.ToManyOrdered<D>) {
|
||||||
|
|
||||||
relationship.nativeValue = NSSet(set: relationship2.nativeValue.set)
|
relationship.nativeValue = NSSet(set: relationship2.nativeValue.set)
|
||||||
}
|
}
|
||||||
@@ -1199,7 +1199,7 @@ extension RelationshipContainer.ToManyUnordered {
|
|||||||
if person.pets.value == anotherPerson.pets.value { ... }
|
if person.pets.value == anotherPerson.pets.value { ... }
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
public static func .== <O2: CoreStoreObject>(_ relationship: RelationshipContainer<O>.ToManyUnordered<D>, _ relationship2: RelationshipContainer<O2>.ToManyUnordered<D>) -> Bool {
|
public static func .== <O2>(_ relationship: RelationshipContainer<O>.ToManyUnordered<D>, _ relationship2: RelationshipContainer<O2>.ToManyUnordered<D>) -> Bool {
|
||||||
|
|
||||||
return relationship.nativeValue.isEqual(relationship2.nativeValue)
|
return relationship.nativeValue.isEqual(relationship2.nativeValue)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,11 +31,11 @@ import CoreData
|
|||||||
|
|
||||||
internal protocol RelationshipProtocol: class {
|
internal protocol RelationshipProtocol: class {
|
||||||
|
|
||||||
var keyPath: KeyPath { get }
|
var keyPath: RawKeyPath { get }
|
||||||
var isToMany: Bool { get }
|
var isToMany: Bool { get }
|
||||||
var isOrdered: Bool { get }
|
var isOrdered: Bool { get }
|
||||||
var deleteRule: NSDeleteRule { get }
|
var deleteRule: NSDeleteRule { get }
|
||||||
var inverse: (type: CoreStoreObject.Type, keyPath: () -> KeyPath?) { get }
|
var inverse: (type: CoreStoreObject.Type, keyPath: () -> RawKeyPath?) { get }
|
||||||
var affectedByKeyPaths: () -> Set<String> { get }
|
var affectedByKeyPaths: () -> Set<String> { get }
|
||||||
weak var parentObject: CoreStoreObject? { get set }
|
weak var parentObject: CoreStoreObject? { get set }
|
||||||
var versionHashModifier: () -> String? { get }
|
var versionHashModifier: () -> String? { get }
|
||||||
|
|||||||
@@ -226,8 +226,6 @@ public final class SQLiteStore: LocalStorage {
|
|||||||
*/
|
*/
|
||||||
public func cs_eraseStorageAndWait(metadata: [String: Any], soureModelHint: NSManagedObjectModel?) throws {
|
public func cs_eraseStorageAndWait(metadata: [String: Any], soureModelHint: NSManagedObjectModel?) throws {
|
||||||
|
|
||||||
// TODO: check if attached to persistent store
|
|
||||||
|
|
||||||
func deleteFiles(storeURL: URL, extraFiles: [String] = []) throws {
|
func deleteFiles(storeURL: URL, extraFiles: [String] = []) throws {
|
||||||
|
|
||||||
let fileManager = FileManager.default
|
let fileManager = FileManager.default
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ public struct SectionBy {
|
|||||||
|
|
||||||
- parameter sectionKeyPath: the key path to use to group the objects into sections
|
- parameter sectionKeyPath: the key path to use to group the objects into sections
|
||||||
*/
|
*/
|
||||||
public init(_ sectionKeyPath: KeyPath) {
|
public init(_ sectionKeyPath: RawKeyPath) {
|
||||||
|
|
||||||
self.init(sectionKeyPath, { $0 })
|
self.init(sectionKeyPath, { $0 })
|
||||||
}
|
}
|
||||||
@@ -59,7 +59,7 @@ public struct SectionBy {
|
|||||||
- parameter sectionKeyPath: the key path to use to group the objects into sections
|
- parameter sectionKeyPath: the key path to use to group the objects into sections
|
||||||
- parameter sectionIndexTransformer: a closure to transform the value for the key path to an appropriate section name
|
- parameter sectionIndexTransformer: a closure to transform the value for the key path to an appropriate section name
|
||||||
*/
|
*/
|
||||||
public init(_ sectionKeyPath: KeyPath, _ sectionIndexTransformer: @escaping (_ sectionName: String?) -> String?) {
|
public init(_ sectionKeyPath: RawKeyPath, _ sectionIndexTransformer: @escaping (_ sectionName: String?) -> String?) {
|
||||||
|
|
||||||
self.sectionKeyPath = sectionKeyPath
|
self.sectionKeyPath = sectionKeyPath
|
||||||
self.sectionIndexTransformer = sectionIndexTransformer
|
self.sectionIndexTransformer = sectionIndexTransformer
|
||||||
@@ -68,6 +68,6 @@ public struct SectionBy {
|
|||||||
|
|
||||||
// MARK: Internal
|
// MARK: Internal
|
||||||
|
|
||||||
internal let sectionKeyPath: KeyPath
|
internal let sectionKeyPath: RawKeyPath
|
||||||
internal let sectionIndexTransformer: (_ sectionName: String?) -> String?
|
internal let sectionIndexTransformer: (_ sectionName: String?) -> String?
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-14
@@ -74,7 +74,7 @@ public enum SelectTerm: ExpressibleByStringLiteral, Hashable {
|
|||||||
- parameter keyPath: the attribute name
|
- parameter keyPath: the attribute name
|
||||||
- returns: a `SelectTerm` to a `Select` clause for querying an entity attribute
|
- returns: a `SelectTerm` to a `Select` clause for querying an entity attribute
|
||||||
*/
|
*/
|
||||||
public static func attribute(_ keyPath: KeyPath) -> SelectTerm {
|
public static func attribute(_ keyPath: RawKeyPath) -> SelectTerm {
|
||||||
|
|
||||||
return ._attribute(keyPath)
|
return ._attribute(keyPath)
|
||||||
}
|
}
|
||||||
@@ -91,7 +91,7 @@ public enum SelectTerm: ExpressibleByStringLiteral, Hashable {
|
|||||||
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "average(<attributeName>)" is used
|
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "average(<attributeName>)" is used
|
||||||
- returns: a `SelectTerm` to a `Select` clause for querying the average value of an attribute
|
- returns: a `SelectTerm` to a `Select` clause for querying the average value of an attribute
|
||||||
*/
|
*/
|
||||||
public static func average(_ keyPath: KeyPath, as alias: KeyPath? = nil) -> SelectTerm {
|
public static func average(_ keyPath: RawKeyPath, as alias: RawKeyPath? = nil) -> SelectTerm {
|
||||||
|
|
||||||
return ._aggregate(
|
return ._aggregate(
|
||||||
function: "average:",
|
function: "average:",
|
||||||
@@ -113,7 +113,7 @@ public enum SelectTerm: ExpressibleByStringLiteral, Hashable {
|
|||||||
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "count(<attributeName>)" is used
|
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "count(<attributeName>)" is used
|
||||||
- returns: a `SelectTerm` to a `Select` clause for a count query
|
- returns: a `SelectTerm` to a `Select` clause for a count query
|
||||||
*/
|
*/
|
||||||
public static func count(_ keyPath: KeyPath, as alias: KeyPath? = nil) -> SelectTerm {
|
public static func count(_ keyPath: RawKeyPath, as alias: RawKeyPath? = nil) -> SelectTerm {
|
||||||
|
|
||||||
return ._aggregate(
|
return ._aggregate(
|
||||||
function: "count:",
|
function: "count:",
|
||||||
@@ -135,7 +135,7 @@ public enum SelectTerm: ExpressibleByStringLiteral, Hashable {
|
|||||||
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "max(<attributeName>)" is used
|
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "max(<attributeName>)" is used
|
||||||
- returns: a `SelectTerm` to a `Select` clause for querying the maximum value for an attribute
|
- returns: a `SelectTerm` to a `Select` clause for querying the maximum value for an attribute
|
||||||
*/
|
*/
|
||||||
public static func maximum(_ keyPath: KeyPath, as alias: KeyPath? = nil) -> SelectTerm {
|
public static func maximum(_ keyPath: RawKeyPath, as alias: RawKeyPath? = nil) -> SelectTerm {
|
||||||
|
|
||||||
return ._aggregate(
|
return ._aggregate(
|
||||||
function: "max:",
|
function: "max:",
|
||||||
@@ -157,7 +157,7 @@ public enum SelectTerm: ExpressibleByStringLiteral, Hashable {
|
|||||||
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "min(<attributeName>)" is used
|
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "min(<attributeName>)" is used
|
||||||
- returns: a `SelectTerm` to a `Select` clause for querying the minimum value for an attribute
|
- returns: a `SelectTerm` to a `Select` clause for querying the minimum value for an attribute
|
||||||
*/
|
*/
|
||||||
public static func minimum(_ keyPath: KeyPath, as alias: KeyPath? = nil) -> SelectTerm {
|
public static func minimum(_ keyPath: RawKeyPath, as alias: RawKeyPath? = nil) -> SelectTerm {
|
||||||
|
|
||||||
return ._aggregate(
|
return ._aggregate(
|
||||||
function: "min:",
|
function: "min:",
|
||||||
@@ -179,7 +179,7 @@ public enum SelectTerm: ExpressibleByStringLiteral, Hashable {
|
|||||||
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "sum(<attributeName>)" is used
|
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "sum(<attributeName>)" is used
|
||||||
- returns: a `SelectTerm` to a `Select` clause for querying the sum value for an attribute
|
- returns: a `SelectTerm` to a `Select` clause for querying the sum value for an attribute
|
||||||
*/
|
*/
|
||||||
public static func sum(_ keyPath: KeyPath, as alias: KeyPath? = nil) -> SelectTerm {
|
public static func sum(_ keyPath: RawKeyPath, as alias: RawKeyPath? = nil) -> SelectTerm {
|
||||||
|
|
||||||
return ._aggregate(
|
return ._aggregate(
|
||||||
function: "sum:",
|
function: "sum:",
|
||||||
@@ -202,7 +202,7 @@ public enum SelectTerm: ExpressibleByStringLiteral, Hashable {
|
|||||||
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "objecID" is used
|
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "objecID" is used
|
||||||
- returns: a `SelectTerm` to a `Select` clause for querying the sum value for an attribute
|
- returns: a `SelectTerm` to a `Select` clause for querying the sum value for an attribute
|
||||||
*/
|
*/
|
||||||
public static func objectID(as alias: KeyPath? = nil) -> SelectTerm {
|
public static func objectID(as alias: RawKeyPath? = nil) -> SelectTerm {
|
||||||
|
|
||||||
return ._identity(
|
return ._identity(
|
||||||
alias: alias ?? "objectID",
|
alias: alias ?? "objectID",
|
||||||
@@ -213,17 +213,17 @@ public enum SelectTerm: ExpressibleByStringLiteral, Hashable {
|
|||||||
|
|
||||||
// MARK: ExpressibleByStringLiteral
|
// MARK: ExpressibleByStringLiteral
|
||||||
|
|
||||||
public init(stringLiteral value: KeyPath) {
|
public init(stringLiteral value: RawKeyPath) {
|
||||||
|
|
||||||
self = ._attribute(value)
|
self = ._attribute(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
public init(unicodeScalarLiteral value: KeyPath) {
|
public init(unicodeScalarLiteral value: RawKeyPath) {
|
||||||
|
|
||||||
self = ._attribute(value)
|
self = ._attribute(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
public init(extendedGraphemeClusterLiteral value: KeyPath) {
|
public init(extendedGraphemeClusterLiteral value: RawKeyPath) {
|
||||||
|
|
||||||
self = ._attribute(value)
|
self = ._attribute(value)
|
||||||
}
|
}
|
||||||
@@ -274,8 +274,8 @@ public enum SelectTerm: ExpressibleByStringLiteral, Hashable {
|
|||||||
|
|
||||||
// MARK: Internal
|
// MARK: Internal
|
||||||
|
|
||||||
case _attribute(KeyPath)
|
case _attribute(RawKeyPath)
|
||||||
case _aggregate(function: String, keyPath: KeyPath, alias: String, nativeType: NSAttributeType)
|
case _aggregate(function: String, keyPath: RawKeyPath, alias: String, nativeType: NSAttributeType)
|
||||||
case _identity(alias: String, nativeType: NSAttributeType)
|
case _identity(alias: String, nativeType: NSAttributeType)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -339,7 +339,7 @@ public struct Select<T: SelectResultType>: Hashable {
|
|||||||
|
|
||||||
// MARK: Equatable
|
// MARK: Equatable
|
||||||
|
|
||||||
public static func == <T: SelectResultType, U: SelectResultType>(lhs: Select<T>, rhs: Select<U>) -> Bool {
|
public static func == <T, U>(lhs: Select<T>, rhs: Select<U>) -> Bool {
|
||||||
|
|
||||||
return lhs.selectTerms == rhs.selectTerms
|
return lhs.selectTerms == rhs.selectTerms
|
||||||
}
|
}
|
||||||
@@ -469,7 +469,7 @@ internal extension Collection where Iterator.Element == SelectTerm {
|
|||||||
fetchRequest.propertiesToFetch = propertiesToFetch
|
fetchRequest.propertiesToFetch = propertiesToFetch
|
||||||
}
|
}
|
||||||
|
|
||||||
internal func keyPathForFirstSelectTerm() -> KeyPath {
|
internal func keyPathForFirstSelectTerm() -> RawKeyPath {
|
||||||
|
|
||||||
switch self.first! {
|
switch self.first! {
|
||||||
|
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ public enum SetupResult<T: StorageInterface>: Hashable {
|
|||||||
|
|
||||||
// MARK: Equatable
|
// MARK: Equatable
|
||||||
|
|
||||||
public static func == <T: StorageInterface, U: StorageInterface>(lhs: SetupResult<T>, rhs: SetupResult<U>) -> Bool {
|
public static func == <T, U>(lhs: SetupResult<T>, rhs: SetupResult<U>) -> Bool {
|
||||||
|
|
||||||
switch (lhs, rhs) {
|
switch (lhs, rhs) {
|
||||||
|
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ public final class SynchronousDataTransaction: BaseDataTransaction {
|
|||||||
- parameter into: the `Into` clause indicating the destination `NSManagedObject` or `CoreStoreObject` entity type and the destination configuration
|
- parameter into: the `Into` clause indicating the destination `NSManagedObject` or `CoreStoreObject` entity type and the destination configuration
|
||||||
- returns: a new `NSManagedObject` or `CoreStoreObject` instance of the specified entity type.
|
- returns: a new `NSManagedObject` or `CoreStoreObject` instance of the specified entity type.
|
||||||
*/
|
*/
|
||||||
public override func create<T: DynamicObject>(_ into: Into<T>) -> T {
|
public override func create<T>(_ into: Into<T>) -> T {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
!self.isCommitted,
|
!self.isCommitted,
|
||||||
@@ -88,7 +88,7 @@ public final class SynchronousDataTransaction: BaseDataTransaction {
|
|||||||
- parameter objectID: the `NSManagedObjectID` for the object to be edited
|
- parameter objectID: the `NSManagedObjectID` for the object to be edited
|
||||||
- returns: an editable proxy for the specified `NSManagedObject` or `CoreStoreObject`.
|
- returns: an editable proxy for the specified `NSManagedObject` or `CoreStoreObject`.
|
||||||
*/
|
*/
|
||||||
public override func edit<T: DynamicObject>(_ into: Into<T>, _ objectID: NSManagedObjectID) -> T? {
|
public override func edit<T>(_ into: Into<T>, _ objectID: NSManagedObjectID) -> T? {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
!self.isCommitted,
|
!self.isCommitted,
|
||||||
@@ -234,9 +234,9 @@ public final class SynchronousDataTransaction: BaseDataTransaction {
|
|||||||
}
|
}
|
||||||
switch childTransaction.result {
|
switch childTransaction.result {
|
||||||
|
|
||||||
case nil: return nil
|
case .none: return nil
|
||||||
case (let hasChanges, nil)?: return SaveResult(hasChanges: hasChanges)
|
case .some(let hasChanges, nil): return SaveResult(hasChanges: hasChanges)
|
||||||
case (_, let error?)?: return SaveResult(error)
|
case .some(_, let error?): return SaveResult(error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-17
@@ -35,9 +35,9 @@ public extension DynamicObject where Self: CoreStoreObject {
|
|||||||
The containing type for transformable properties. `Transformable` properties support types that conforms to `NSCoding & NSCopying`.
|
The containing type for transformable properties. `Transformable` properties support types that conforms to `NSCoding & NSCopying`.
|
||||||
```
|
```
|
||||||
class Animal: CoreStoreObject {
|
class Animal: CoreStoreObject {
|
||||||
let species = Value.Required<String>("species")
|
let species = Value.Required<String>("species", initial: "")
|
||||||
let nickname = Value.Optional<String>("nickname")
|
let nickname = Value.Optional<String>("nickname")
|
||||||
let color = Transformable.Optional<UIColor>("color")
|
let color = Transformable.Optional<UIColor>("color")
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
- Important: `Transformable` properties are required to be stored properties. Computed properties will be ignored, including `lazy` and `weak` properties.
|
- Important: `Transformable` properties are required to be stored properties. Computed properties will be ignored, including `lazy` and `weak` properties.
|
||||||
@@ -52,7 +52,7 @@ public extension DynamicObject where Self: CoreStoreObject {
|
|||||||
The containing type for transformable properties. Use the `DynamicObject.Transformable` typealias instead for shorter syntax.
|
The containing type for transformable properties. Use the `DynamicObject.Transformable` typealias instead for shorter syntax.
|
||||||
```
|
```
|
||||||
class Animal: CoreStoreObject {
|
class Animal: CoreStoreObject {
|
||||||
let species = Value.Required<String>("species")
|
let species = Value.Required<String>("species", initial: "")
|
||||||
let nickname = Value.Optional<String>("nickname")
|
let nickname = Value.Optional<String>("nickname")
|
||||||
let color = Transformable.Optional<UIColor>("color")
|
let color = Transformable.Optional<UIColor>("color")
|
||||||
}
|
}
|
||||||
@@ -66,7 +66,7 @@ public enum TransformableContainer<O: CoreStoreObject> {
|
|||||||
The containing type for transformable properties. Any type that conforms to `NSCoding & NSCopying` are supported.
|
The containing type for transformable properties. Any type that conforms to `NSCoding & NSCopying` are supported.
|
||||||
```
|
```
|
||||||
class Animal: CoreStoreObject {
|
class Animal: CoreStoreObject {
|
||||||
let species = Value.Required<String>("species")
|
let species = Value.Required<String>("species", initial: "")
|
||||||
let nickname = Value.Optional<String>("nickname")
|
let nickname = Value.Optional<String>("nickname")
|
||||||
let color = Transformable.Optional<UIColor>("color")
|
let color = Transformable.Optional<UIColor>("color")
|
||||||
}
|
}
|
||||||
@@ -79,7 +79,7 @@ public enum TransformableContainer<O: CoreStoreObject> {
|
|||||||
Initializes the metadata for the property.
|
Initializes the metadata for the property.
|
||||||
```
|
```
|
||||||
class Animal: CoreStoreObject {
|
class Animal: CoreStoreObject {
|
||||||
let species = Value.Required<String>("species")
|
let species = Value.Required<String>("species", initial: "")
|
||||||
let color = Transformable.Required<UIColor>(
|
let color = Transformable.Required<UIColor>(
|
||||||
"color",
|
"color",
|
||||||
initial: UIColor.clear,
|
initial: UIColor.clear,
|
||||||
@@ -116,7 +116,7 @@ public enum TransformableContainer<O: CoreStoreObject> {
|
|||||||
- parameter affectedByKeyPaths: a set of key paths for properties whose values affect the value of the receiver. This is similar to `NSManagedObject.keyPathsForValuesAffectingValue(forKey:)`.
|
- parameter affectedByKeyPaths: a set of key paths for properties whose values affect the value of the receiver. This is similar to `NSManagedObject.keyPathsForValuesAffectingValue(forKey:)`.
|
||||||
*/
|
*/
|
||||||
public init(
|
public init(
|
||||||
_ keyPath: KeyPath,
|
_ keyPath: RawKeyPath,
|
||||||
initial: @autoclosure @escaping () -> V,
|
initial: @autoclosure @escaping () -> V,
|
||||||
isIndexed: Bool = false,
|
isIndexed: Bool = false,
|
||||||
isTransient: Bool = false,
|
isTransient: Bool = false,
|
||||||
@@ -197,7 +197,7 @@ public enum TransformableContainer<O: CoreStoreObject> {
|
|||||||
return .transformableAttributeType
|
return .transformableAttributeType
|
||||||
}
|
}
|
||||||
|
|
||||||
public let keyPath: KeyPath
|
public let keyPath: RawKeyPath
|
||||||
|
|
||||||
internal let isOptional = false
|
internal let isOptional = false
|
||||||
internal let isIndexed: Bool
|
internal let isIndexed: Bool
|
||||||
@@ -259,9 +259,9 @@ public enum TransformableContainer<O: CoreStoreObject> {
|
|||||||
|
|
||||||
// MARK: Deprecated
|
// MARK: Deprecated
|
||||||
|
|
||||||
@available(*, deprecated: 3.1, renamed: "init(_:initial:isIndexed:isTransient:versionHashModifier:renamingIdentifier:customGetter:customSetter:affectedByKeyPaths:)")
|
@available(*, deprecated: 3.2, renamed: "init(_:initial:isIndexed:isTransient:versionHashModifier:renamingIdentifier:customGetter:customSetter:affectedByKeyPaths:)")
|
||||||
public convenience init(
|
public convenience init(
|
||||||
_ keyPath: KeyPath,
|
_ keyPath: RawKeyPath,
|
||||||
`default`: @autoclosure @escaping () -> V,
|
`default`: @autoclosure @escaping () -> V,
|
||||||
isIndexed: Bool = false,
|
isIndexed: Bool = false,
|
||||||
isTransient: Bool = false,
|
isTransient: Bool = false,
|
||||||
@@ -292,7 +292,7 @@ public enum TransformableContainer<O: CoreStoreObject> {
|
|||||||
The containing type for optional transformable properties. Any type that conforms to `NSCoding & NSCopying` are supported.
|
The containing type for optional transformable properties. Any type that conforms to `NSCoding & NSCopying` are supported.
|
||||||
```
|
```
|
||||||
class Animal: CoreStoreObject {
|
class Animal: CoreStoreObject {
|
||||||
let species = Value.Required<String>("species")
|
let species = Value.Required<String>("species", initial: "")
|
||||||
let nickname = Value.Optional<String>("nickname")
|
let nickname = Value.Optional<String>("nickname")
|
||||||
let color = Transformable.Optional<UIColor>("color")
|
let color = Transformable.Optional<UIColor>("color")
|
||||||
}
|
}
|
||||||
@@ -305,7 +305,7 @@ public enum TransformableContainer<O: CoreStoreObject> {
|
|||||||
Initializes the metadata for the property.
|
Initializes the metadata for the property.
|
||||||
```
|
```
|
||||||
class Animal: CoreStoreObject {
|
class Animal: CoreStoreObject {
|
||||||
let species = Value.Required<String>("species")
|
let species = Value.Required<String>("species", initial: "")
|
||||||
let color = Transformable.Optional<UIColor>(
|
let color = Transformable.Optional<UIColor>(
|
||||||
"color",
|
"color",
|
||||||
isTransient: true,
|
isTransient: true,
|
||||||
@@ -339,7 +339,7 @@ public enum TransformableContainer<O: CoreStoreObject> {
|
|||||||
- parameter affectedByKeyPaths: a set of key paths for properties whose values affect the value of the receiver. This is similar to `NSManagedObject.keyPathsForValuesAffectingValue(forKey:)`.
|
- parameter affectedByKeyPaths: a set of key paths for properties whose values affect the value of the receiver. This is similar to `NSManagedObject.keyPathsForValuesAffectingValue(forKey:)`.
|
||||||
*/
|
*/
|
||||||
public init(
|
public init(
|
||||||
_ keyPath: KeyPath,
|
_ keyPath: RawKeyPath,
|
||||||
initial: @autoclosure @escaping () -> V? = nil,
|
initial: @autoclosure @escaping () -> V? = nil,
|
||||||
isIndexed: Bool = false,
|
isIndexed: Bool = false,
|
||||||
isTransient: Bool = false,
|
isTransient: Bool = false,
|
||||||
@@ -420,7 +420,7 @@ public enum TransformableContainer<O: CoreStoreObject> {
|
|||||||
return .transformableAttributeType
|
return .transformableAttributeType
|
||||||
}
|
}
|
||||||
|
|
||||||
public let keyPath: KeyPath
|
public let keyPath: RawKeyPath
|
||||||
|
|
||||||
internal let isOptional = true
|
internal let isOptional = true
|
||||||
internal let isIndexed: Bool
|
internal let isIndexed: Bool
|
||||||
@@ -482,10 +482,10 @@ public enum TransformableContainer<O: CoreStoreObject> {
|
|||||||
|
|
||||||
// MARK: Deprecated
|
// MARK: Deprecated
|
||||||
|
|
||||||
@available(*, deprecated: 3.1, renamed: "init(_:initial:isIndexed:isTransient:versionHashModifier:renamingIdentifier:customGetter:customSetter:affectedByKeyPaths:)")
|
@available(*, deprecated: 3.2, renamed: "init(_:initial:isIndexed:isTransient:versionHashModifier:renamingIdentifier:customGetter:customSetter:affectedByKeyPaths:)")
|
||||||
public convenience init(
|
public convenience init(
|
||||||
_ keyPath: KeyPath,
|
_ keyPath: RawKeyPath,
|
||||||
`default`: @autoclosure @escaping () -> V?,
|
`default`: @autoclosure @escaping () -> V? = nil,
|
||||||
isIndexed: Bool = false,
|
isIndexed: Bool = false,
|
||||||
isTransient: Bool = false,
|
isTransient: Bool = false,
|
||||||
versionHashModifier: @autoclosure @escaping () -> String? = nil,
|
versionHashModifier: @autoclosure @escaping () -> String? = nil,
|
||||||
|
|||||||
+1
-1
@@ -63,7 +63,7 @@ public struct Tweak: FetchClause, QueryClause, DeleteClause {
|
|||||||
|
|
||||||
// MARK: FetchClause, QueryClause, DeleteClause
|
// MARK: FetchClause, QueryClause, DeleteClause
|
||||||
|
|
||||||
public func applyToFetchRequest<ResultType: NSFetchRequestResult>(_ fetchRequest: NSFetchRequest<ResultType>) {
|
public func applyToFetchRequest<ResultType>(_ fetchRequest: NSFetchRequest<ResultType>) {
|
||||||
|
|
||||||
self.closure(fetchRequest as! NSFetchRequest<NSFetchRequestResult>)
|
self.closure(fetchRequest as! NSFetchRequest<NSFetchRequestResult>)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ public extension UnsafeDataTransaction {
|
|||||||
- parameter object: the `DynamicObject` to observe changes from
|
- parameter object: the `DynamicObject` to observe changes from
|
||||||
- returns: a `ObjectMonitor` that monitors changes to `object`
|
- returns: a `ObjectMonitor` that monitors changes to `object`
|
||||||
*/
|
*/
|
||||||
public func monitorObject<T: DynamicObject>(_ object: T) -> ObjectMonitor<T> {
|
public func monitorObject<T>(_ object: T) -> ObjectMonitor<T> {
|
||||||
|
|
||||||
return ObjectMonitor(
|
return ObjectMonitor(
|
||||||
unsafeTransaction: self,
|
unsafeTransaction: self,
|
||||||
@@ -53,7 +53,7 @@ public extension UnsafeDataTransaction {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: a `ListMonitor` instance that monitors changes to the list
|
- returns: a `ListMonitor` instance that monitors changes to the list
|
||||||
*/
|
*/
|
||||||
public func monitorList<T: DynamicObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> ListMonitor<T> {
|
public func monitorList<T>(_ from: From<T>, _ fetchClauses: FetchClause...) -> ListMonitor<T> {
|
||||||
|
|
||||||
return self.monitorList(from, fetchClauses)
|
return self.monitorList(from, fetchClauses)
|
||||||
}
|
}
|
||||||
@@ -65,7 +65,7 @@ public extension UnsafeDataTransaction {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: a `ListMonitor` instance that monitors changes to the list
|
- returns: a `ListMonitor` instance that monitors changes to the list
|
||||||
*/
|
*/
|
||||||
public func monitorList<T: DynamicObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> ListMonitor<T> {
|
public func monitorList<T>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> ListMonitor<T> {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
fetchClauses.filter { $0 is OrderBy }.count > 0,
|
fetchClauses.filter { $0 is OrderBy }.count > 0,
|
||||||
@@ -90,7 +90,7 @@ public extension UnsafeDataTransaction {
|
|||||||
- parameter from: a `From` clause indicating the entity type
|
- parameter from: a `From` clause indicating the entity type
|
||||||
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
*/
|
*/
|
||||||
public func monitorList<T: DynamicObject>(createAsynchronously: @escaping (ListMonitor<T>) -> Void, _ from: From<T>, _ fetchClauses: FetchClause...) {
|
public func monitorList<T>(createAsynchronously: @escaping (ListMonitor<T>) -> Void, _ from: From<T>, _ fetchClauses: FetchClause...) {
|
||||||
|
|
||||||
self.monitorList(createAsynchronously: createAsynchronously, from, fetchClauses)
|
self.monitorList(createAsynchronously: createAsynchronously, from, fetchClauses)
|
||||||
}
|
}
|
||||||
@@ -102,7 +102,7 @@ public extension UnsafeDataTransaction {
|
|||||||
- parameter from: a `From` clause indicating the entity type
|
- parameter from: a `From` clause indicating the entity type
|
||||||
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
*/
|
*/
|
||||||
public func monitorList<T: DynamicObject>(createAsynchronously: @escaping (ListMonitor<T>) -> Void, _ from: From<T>, _ fetchClauses: [FetchClause]) {
|
public func monitorList<T>(createAsynchronously: @escaping (ListMonitor<T>) -> Void, _ from: From<T>, _ fetchClauses: [FetchClause]) {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
fetchClauses.filter { $0 is OrderBy }.count > 0,
|
fetchClauses.filter { $0 is OrderBy }.count > 0,
|
||||||
@@ -129,7 +129,7 @@ public extension UnsafeDataTransaction {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: a `ListMonitor` instance that monitors changes to the list
|
- returns: a `ListMonitor` instance that monitors changes to the list
|
||||||
*/
|
*/
|
||||||
public func monitorSectionedList<T: DynamicObject>(_ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) -> ListMonitor<T> {
|
public func monitorSectionedList<T>(_ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) -> ListMonitor<T> {
|
||||||
|
|
||||||
return self.monitorSectionedList(from, sectionBy, fetchClauses)
|
return self.monitorSectionedList(from, sectionBy, fetchClauses)
|
||||||
}
|
}
|
||||||
@@ -142,7 +142,7 @@ public extension UnsafeDataTransaction {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: a `ListMonitor` instance that monitors changes to the list
|
- returns: a `ListMonitor` instance that monitors changes to the list
|
||||||
*/
|
*/
|
||||||
public func monitorSectionedList<T: DynamicObject>(_ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) -> ListMonitor<T> {
|
public func monitorSectionedList<T>(_ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) -> ListMonitor<T> {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
fetchClauses.filter { $0 is OrderBy }.count > 0,
|
fetchClauses.filter { $0 is OrderBy }.count > 0,
|
||||||
@@ -168,7 +168,7 @@ public extension UnsafeDataTransaction {
|
|||||||
- parameter sectionBy: a `SectionBy` clause indicating the keyPath for the attribute to use when sorting the list into sections.
|
- parameter sectionBy: a `SectionBy` clause indicating the keyPath for the attribute to use when sorting the list into sections.
|
||||||
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
*/
|
*/
|
||||||
public func monitorSectionedList<T: DynamicObject>(createAsynchronously: @escaping (ListMonitor<T>) -> Void, _ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) {
|
public func monitorSectionedList<T>(createAsynchronously: @escaping (ListMonitor<T>) -> Void, _ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) {
|
||||||
|
|
||||||
self.monitorSectionedList(createAsynchronously: createAsynchronously, from, sectionBy, fetchClauses)
|
self.monitorSectionedList(createAsynchronously: createAsynchronously, from, sectionBy, fetchClauses)
|
||||||
}
|
}
|
||||||
@@ -181,7 +181,7 @@ public extension UnsafeDataTransaction {
|
|||||||
- parameter sectionBy: a `SectionBy` clause indicating the keyPath for the attribute to use when sorting the list into sections.
|
- parameter sectionBy: a `SectionBy` clause indicating the keyPath for the attribute to use when sorting the list into sections.
|
||||||
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
*/
|
*/
|
||||||
public func monitorSectionedList<T: DynamicObject>(createAsynchronously: @escaping (ListMonitor<T>) -> Void, _ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) {
|
public func monitorSectionedList<T>(createAsynchronously: @escaping (ListMonitor<T>) -> Void, _ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
fetchClauses.filter { $0 is OrderBy }.count > 0,
|
fetchClauses.filter { $0 is OrderBy }.count > 0,
|
||||||
|
|||||||
+30
-29
@@ -35,7 +35,7 @@ public extension DynamicObject where Self: CoreStoreObject {
|
|||||||
The containing type for value propertiess. `Value` properties support any type that conforms to `ImportableAttributeType`.
|
The containing type for value propertiess. `Value` properties support any type that conforms to `ImportableAttributeType`.
|
||||||
```
|
```
|
||||||
class Animal: CoreStoreObject {
|
class Animal: CoreStoreObject {
|
||||||
let species = Value.Required<String>("species")
|
let species = Value.Required<String>("species", initial: "")
|
||||||
let nickname = Value.Optional<String>("nickname")
|
let nickname = Value.Optional<String>("nickname")
|
||||||
let color = Transformable.Optional<UIColor>("color")
|
let color = Transformable.Optional<UIColor>("color")
|
||||||
}
|
}
|
||||||
@@ -52,7 +52,7 @@ public extension DynamicObject where Self: CoreStoreObject {
|
|||||||
The containing type for value properties. Use the `DynamicObject.Value` typealias instead for shorter syntax.
|
The containing type for value properties. Use the `DynamicObject.Value` typealias instead for shorter syntax.
|
||||||
```
|
```
|
||||||
class Animal: CoreStoreObject {
|
class Animal: CoreStoreObject {
|
||||||
let species = Value.Required<String>("species")
|
let species = Value.Required<String>("species", initial: "")
|
||||||
let nickname = Value.Optional<String>("nickname")
|
let nickname = Value.Optional<String>("nickname")
|
||||||
let color = Transformable.Optional<UIColor>("color")
|
let color = Transformable.Optional<UIColor>("color")
|
||||||
}
|
}
|
||||||
@@ -66,7 +66,7 @@ public enum ValueContainer<O: CoreStoreObject> {
|
|||||||
The containing type for required value properties. Any type that conforms to `ImportableAttributeType` are supported.
|
The containing type for required value properties. Any type that conforms to `ImportableAttributeType` are supported.
|
||||||
```
|
```
|
||||||
class Animal: CoreStoreObject {
|
class Animal: CoreStoreObject {
|
||||||
let species = Value.Required<String>("species")
|
let species = Value.Required<String>("species", initial: "")
|
||||||
let nickname = Value.Optional<String>("nickname")
|
let nickname = Value.Optional<String>("nickname")
|
||||||
let color = Transformable.Optional<UIColor>("color")
|
let color = Transformable.Optional<UIColor>("color")
|
||||||
}
|
}
|
||||||
@@ -80,9 +80,10 @@ public enum ValueContainer<O: CoreStoreObject> {
|
|||||||
```
|
```
|
||||||
class Person: CoreStoreObject {
|
class Person: CoreStoreObject {
|
||||||
let title = Value.Required<String>("title", initial: "Mr.")
|
let title = Value.Required<String>("title", initial: "Mr.")
|
||||||
let name = Value.Required<String>("name")
|
let name = Value.Required<String>("name", initial: "")
|
||||||
let displayName = Value.Required<String>(
|
let displayName = Value.Required<String>(
|
||||||
"displayName",
|
"displayName",
|
||||||
|
initial: "",
|
||||||
isTransient: true,
|
isTransient: true,
|
||||||
customGetter: Person.getName(_:)
|
customGetter: Person.getName(_:)
|
||||||
)
|
)
|
||||||
@@ -111,7 +112,7 @@ public enum ValueContainer<O: CoreStoreObject> {
|
|||||||
- parameter affectedByKeyPaths: a set of key paths for properties whose values affect the value of the receiver. This is similar to `NSManagedObject.keyPathsForValuesAffectingValue(forKey:)`.
|
- parameter affectedByKeyPaths: a set of key paths for properties whose values affect the value of the receiver. This is similar to `NSManagedObject.keyPathsForValuesAffectingValue(forKey:)`.
|
||||||
*/
|
*/
|
||||||
public init(
|
public init(
|
||||||
_ keyPath: KeyPath,
|
_ keyPath: RawKeyPath,
|
||||||
initial: @autoclosure @escaping () -> V,
|
initial: @autoclosure @escaping () -> V,
|
||||||
isIndexed: Bool = false,
|
isIndexed: Bool = false,
|
||||||
isTransient: Bool = false,
|
isTransient: Bool = false,
|
||||||
@@ -124,7 +125,7 @@ public enum ValueContainer<O: CoreStoreObject> {
|
|||||||
self.keyPath = keyPath
|
self.keyPath = keyPath
|
||||||
self.isIndexed = isIndexed
|
self.isIndexed = isIndexed
|
||||||
self.isTransient = isTransient
|
self.isTransient = isTransient
|
||||||
self.defaultValue = { initial().cs_toImportableNativeType() }
|
self.defaultValue = { initial().cs_toQueryableNativeType() }
|
||||||
self.versionHashModifier = versionHashModifier
|
self.versionHashModifier = versionHashModifier
|
||||||
self.renamingIdentifier = renamingIdentifier
|
self.renamingIdentifier = renamingIdentifier
|
||||||
self.customGetter = customGetter
|
self.customGetter = customGetter
|
||||||
@@ -153,8 +154,8 @@ public enum ValueContainer<O: CoreStoreObject> {
|
|||||||
|
|
||||||
return customGetter(PartialObject<O>(object.rawObject!))
|
return customGetter(PartialObject<O>(object.rawObject!))
|
||||||
}
|
}
|
||||||
return V.cs_fromImportableNativeType(
|
return V.cs_fromQueryableNativeType(
|
||||||
object.rawObject!.value(forKey: self.keyPath)! as! V.ImportableNativeType
|
object.rawObject!.value(forKey: self.keyPath)! as! V.QueryableNativeType
|
||||||
)!
|
)!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -179,7 +180,7 @@ public enum ValueContainer<O: CoreStoreObject> {
|
|||||||
return customSetter(PartialObject<O>(object.rawObject!), newValue)
|
return customSetter(PartialObject<O>(object.rawObject!), newValue)
|
||||||
}
|
}
|
||||||
return object.rawObject!.setValue(
|
return object.rawObject!.setValue(
|
||||||
newValue.cs_toImportableNativeType(),
|
newValue.cs_toQueryableNativeType(),
|
||||||
forKey: self.keyPath
|
forKey: self.keyPath
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -194,7 +195,7 @@ public enum ValueContainer<O: CoreStoreObject> {
|
|||||||
return V.cs_rawAttributeType
|
return V.cs_rawAttributeType
|
||||||
}
|
}
|
||||||
|
|
||||||
public let keyPath: KeyPath
|
public let keyPath: RawKeyPath
|
||||||
|
|
||||||
internal let isOptional = false
|
internal let isOptional = false
|
||||||
internal let isIndexed: Bool
|
internal let isIndexed: Bool
|
||||||
@@ -221,7 +222,7 @@ public enum ValueContainer<O: CoreStoreObject> {
|
|||||||
rawObject.didAccessValue(forKey: keyPath)
|
rawObject.didAccessValue(forKey: keyPath)
|
||||||
}
|
}
|
||||||
let value = customGetter(PartialObject<O>(rawObject))
|
let value = customGetter(PartialObject<O>(rawObject))
|
||||||
return value.cs_toImportableNativeType()
|
return value.cs_toQueryableNativeType()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -242,7 +243,7 @@ public enum ValueContainer<O: CoreStoreObject> {
|
|||||||
}
|
}
|
||||||
customSetter(
|
customSetter(
|
||||||
PartialObject<O>(rawObject),
|
PartialObject<O>(rawObject),
|
||||||
V.cs_fromImportableNativeType(newValue as! V.ImportableNativeType)!
|
V.cs_fromQueryableNativeType(newValue as! V.QueryableNativeType)!
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -256,9 +257,9 @@ public enum ValueContainer<O: CoreStoreObject> {
|
|||||||
|
|
||||||
// MARK: Deprecated
|
// MARK: Deprecated
|
||||||
|
|
||||||
@available(*, deprecated: 3.1, renamed: "init(_:initial:isIndexed:isTransient:versionHashModifier:renamingIdentifier:customGetter:customSetter:affectedByKeyPaths:)")
|
@available(*, deprecated: 3.2, renamed: "init(_:initial:isIndexed:isTransient:versionHashModifier:renamingIdentifier:customGetter:customSetter:affectedByKeyPaths:)")
|
||||||
public convenience init(
|
public convenience init(
|
||||||
_ keyPath: KeyPath,
|
_ keyPath: RawKeyPath,
|
||||||
`default`: @autoclosure @escaping () -> V,
|
`default`: @autoclosure @escaping () -> V,
|
||||||
isIndexed: Bool = false,
|
isIndexed: Bool = false,
|
||||||
isTransient: Bool = false,
|
isTransient: Bool = false,
|
||||||
@@ -289,7 +290,7 @@ public enum ValueContainer<O: CoreStoreObject> {
|
|||||||
The containing type for optional value properties. Any type that conforms to `ImportableAttributeType` are supported.
|
The containing type for optional value properties. Any type that conforms to `ImportableAttributeType` are supported.
|
||||||
```
|
```
|
||||||
class Animal: CoreStoreObject {
|
class Animal: CoreStoreObject {
|
||||||
let species = Value.Required<String>("species")
|
let species = Value.Required<String>("species", initial: "")
|
||||||
let nickname = Value.Optional<String>("nickname")
|
let nickname = Value.Optional<String>("nickname")
|
||||||
let color = Transformable.Optional<UIColor>("color")
|
let color = Transformable.Optional<UIColor>("color")
|
||||||
}
|
}
|
||||||
@@ -338,7 +339,7 @@ public enum ValueContainer<O: CoreStoreObject> {
|
|||||||
- parameter affectedByKeyPaths: a set of key paths for properties whose values affect the value of the receiver. This is similar to `NSManagedObject.keyPathsForValuesAffectingValue(forKey:)`.
|
- parameter affectedByKeyPaths: a set of key paths for properties whose values affect the value of the receiver. This is similar to `NSManagedObject.keyPathsForValuesAffectingValue(forKey:)`.
|
||||||
*/
|
*/
|
||||||
public init(
|
public init(
|
||||||
_ keyPath: KeyPath,
|
_ keyPath: RawKeyPath,
|
||||||
initial: @autoclosure @escaping () -> V? = nil,
|
initial: @autoclosure @escaping () -> V? = nil,
|
||||||
isIndexed: Bool = false,
|
isIndexed: Bool = false,
|
||||||
isTransient: Bool = false,
|
isTransient: Bool = false,
|
||||||
@@ -351,7 +352,7 @@ public enum ValueContainer<O: CoreStoreObject> {
|
|||||||
self.keyPath = keyPath
|
self.keyPath = keyPath
|
||||||
self.isIndexed = isIndexed
|
self.isIndexed = isIndexed
|
||||||
self.isTransient = isTransient
|
self.isTransient = isTransient
|
||||||
self.defaultValue = { initial()?.cs_toImportableNativeType() }
|
self.defaultValue = { initial()?.cs_toQueryableNativeType() }
|
||||||
self.versionHashModifier = versionHashModifier
|
self.versionHashModifier = versionHashModifier
|
||||||
self.renamingIdentifier = renamingIdentifier
|
self.renamingIdentifier = renamingIdentifier
|
||||||
self.customGetter = customGetter
|
self.customGetter = customGetter
|
||||||
@@ -380,8 +381,8 @@ public enum ValueContainer<O: CoreStoreObject> {
|
|||||||
|
|
||||||
return customGetter(PartialObject<O>(object.rawObject!))
|
return customGetter(PartialObject<O>(object.rawObject!))
|
||||||
}
|
}
|
||||||
return (object.rawObject!.value(forKey: self.keyPath) as! V.ImportableNativeType?)
|
return (object.rawObject!.value(forKey: self.keyPath) as! V.QueryableNativeType?)
|
||||||
.flatMap(V.cs_fromImportableNativeType)
|
.flatMap(V.cs_fromQueryableNativeType)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
@@ -405,7 +406,7 @@ public enum ValueContainer<O: CoreStoreObject> {
|
|||||||
return customSetter(PartialObject<O>(object.rawObject!), newValue)
|
return customSetter(PartialObject<O>(object.rawObject!), newValue)
|
||||||
}
|
}
|
||||||
object.rawObject!.setValue(
|
object.rawObject!.setValue(
|
||||||
newValue?.cs_toImportableNativeType(),
|
newValue?.cs_toQueryableNativeType(),
|
||||||
forKey: self.keyPath
|
forKey: self.keyPath
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -420,7 +421,7 @@ public enum ValueContainer<O: CoreStoreObject> {
|
|||||||
return V.cs_rawAttributeType
|
return V.cs_rawAttributeType
|
||||||
}
|
}
|
||||||
|
|
||||||
public let keyPath: KeyPath
|
public let keyPath: RawKeyPath
|
||||||
internal let isOptional = true
|
internal let isOptional = true
|
||||||
internal let isIndexed: Bool
|
internal let isIndexed: Bool
|
||||||
internal let isTransient: Bool
|
internal let isTransient: Bool
|
||||||
@@ -446,7 +447,7 @@ public enum ValueContainer<O: CoreStoreObject> {
|
|||||||
rawObject.didAccessValue(forKey: keyPath)
|
rawObject.didAccessValue(forKey: keyPath)
|
||||||
}
|
}
|
||||||
let value = customGetter(PartialObject<O>(rawObject))
|
let value = customGetter(PartialObject<O>(rawObject))
|
||||||
return value?.cs_toImportableNativeType()
|
return value?.cs_toQueryableNativeType()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -467,7 +468,7 @@ public enum ValueContainer<O: CoreStoreObject> {
|
|||||||
}
|
}
|
||||||
customSetter(
|
customSetter(
|
||||||
PartialObject<O>(rawObject),
|
PartialObject<O>(rawObject),
|
||||||
(newValue as! V.ImportableNativeType?).flatMap(V.cs_fromImportableNativeType)
|
(newValue as! V.QueryableNativeType?).flatMap(V.cs_fromQueryableNativeType)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -481,10 +482,10 @@ public enum ValueContainer<O: CoreStoreObject> {
|
|||||||
|
|
||||||
// MARK: Deprecated
|
// MARK: Deprecated
|
||||||
|
|
||||||
@available(*, deprecated: 3.1, renamed: "init(_:initial:isIndexed:isTransient:versionHashModifier:renamingIdentifier:customGetter:customSetter:affectedByKeyPaths:)")
|
@available(*, deprecated: 3.2, renamed: "init(_:initial:isIndexed:isTransient:versionHashModifier:renamingIdentifier:customGetter:customSetter:affectedByKeyPaths:)")
|
||||||
public convenience init(
|
public convenience init(
|
||||||
_ keyPath: KeyPath,
|
_ keyPath: RawKeyPath,
|
||||||
`default`: @autoclosure @escaping () -> V?,
|
`default`: @autoclosure @escaping () -> V? = nil,
|
||||||
isIndexed: Bool = false,
|
isIndexed: Bool = false,
|
||||||
isTransient: Bool = false,
|
isTransient: Bool = false,
|
||||||
versionHashModifier: @autoclosure @escaping () -> String? = nil,
|
versionHashModifier: @autoclosure @escaping () -> String? = nil,
|
||||||
@@ -541,7 +542,7 @@ extension ValueContainer.Required {
|
|||||||
animal.species.value = anotherAnimal.species.value
|
animal.species.value = anotherAnimal.species.value
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
public static func .= <O2: CoreStoreObject>(_ property: ValueContainer<O>.Required<V>, _ property2: ValueContainer<O2>.Required<V>) {
|
public static func .= <O2>(_ property: ValueContainer<O>.Required<V>, _ property2: ValueContainer<O2>.Required<V>) {
|
||||||
|
|
||||||
property.value = property2.value
|
property.value = property2.value
|
||||||
}
|
}
|
||||||
@@ -634,7 +635,7 @@ extension ValueContainer.Optional {
|
|||||||
animal.nickname.value = anotherAnimal.nickname.value
|
animal.nickname.value = anotherAnimal.nickname.value
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
public static func .= <O2: CoreStoreObject>(_ property: ValueContainer<O>.Optional<V>, _ property2: ValueContainer<O2>.Optional<V>) {
|
public static func .= <O2>(_ property: ValueContainer<O>.Optional<V>, _ property2: ValueContainer<O2>.Optional<V>) {
|
||||||
|
|
||||||
property.value = property2.value
|
property.value = property2.value
|
||||||
}
|
}
|
||||||
@@ -649,7 +650,7 @@ extension ValueContainer.Optional {
|
|||||||
animal.nickname.value = anotherAnimal.species.value
|
animal.nickname.value = anotherAnimal.species.value
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
public static func .= <O2: CoreStoreObject>(_ property: ValueContainer<O>.Optional<V>, _ property2: ValueContainer<O2>.Required<V>) {
|
public static func .= <O2>(_ property: ValueContainer<O>.Optional<V>, _ property2: ValueContainer<O2>.Required<V>) {
|
||||||
|
|
||||||
property.value = property2.value
|
property.value = property2.value
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,12 +32,12 @@ import Foundation
|
|||||||
The `VersionLock` contains the version hashes for entities. This is then passed to the `CoreStoreSchema`, which contains all entities for the store. An assertion will be raised if any `Entity` doesn't match the version hash.
|
The `VersionLock` contains the version hashes for entities. This is then passed to the `CoreStoreSchema`, which contains all entities for the store. An assertion will be raised if any `Entity` doesn't match the version hash.
|
||||||
```
|
```
|
||||||
class Animal: CoreStoreObject {
|
class Animal: CoreStoreObject {
|
||||||
let species = Value.Required<String>("species")
|
let species = Value.Required<String>("species", initial: "")
|
||||||
let nickname = Value.Optional<String>("nickname")
|
let nickname = Value.Optional<String>("nickname")
|
||||||
let master = Relationship.ToOne<Person>("master")
|
let master = Relationship.ToOne<Person>("master")
|
||||||
}
|
}
|
||||||
class Person: CoreStoreObject {
|
class Person: CoreStoreObject {
|
||||||
let name = Value.Required<String>("name")
|
let name = Value.Required<String>("name", initial: "")
|
||||||
let pet = Relationship.ToOne<Animal>("pet", inverse: { $0.master })
|
let pet = Relationship.ToOne<Animal>("pet", inverse: { $0.master })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+6
-6
@@ -169,7 +169,7 @@ public struct Where: FetchClause, QueryClause, DeleteClause, Hashable {
|
|||||||
- parameter keyPath: the keyPath to compare with
|
- parameter keyPath: the keyPath to compare with
|
||||||
- parameter value: the arguments for the `==` operator
|
- parameter value: the arguments for the `==` operator
|
||||||
*/
|
*/
|
||||||
public init(_ keyPath: KeyPath, isEqualTo value: Void?) {
|
public init(_ keyPath: RawKeyPath, isEqualTo value: Void?) {
|
||||||
|
|
||||||
self.init(NSPredicate(format: "\(keyPath) == nil"))
|
self.init(NSPredicate(format: "\(keyPath) == nil"))
|
||||||
}
|
}
|
||||||
@@ -180,7 +180,7 @@ public struct Where: FetchClause, QueryClause, DeleteClause, Hashable {
|
|||||||
- parameter keyPath: the keyPath to compare with
|
- parameter keyPath: the keyPath to compare with
|
||||||
- parameter value: the arguments for the `==` operator
|
- parameter value: the arguments for the `==` operator
|
||||||
*/
|
*/
|
||||||
public init<T: QueryableAttributeType>(_ keyPath: KeyPath, isEqualTo value: T?) {
|
public init<T: QueryableAttributeType>(_ keyPath: RawKeyPath, isEqualTo value: T?) {
|
||||||
|
|
||||||
switch value {
|
switch value {
|
||||||
|
|
||||||
@@ -199,7 +199,7 @@ public struct Where: FetchClause, QueryClause, DeleteClause, Hashable {
|
|||||||
- parameter keyPath: the keyPath to compare with
|
- parameter keyPath: the keyPath to compare with
|
||||||
- parameter object: the arguments for the `==` operator
|
- parameter object: the arguments for the `==` operator
|
||||||
*/
|
*/
|
||||||
public init<T: DynamicObject>(_ keyPath: KeyPath, isEqualTo object: T?) {
|
public init<T: DynamicObject>(_ keyPath: RawKeyPath, isEqualTo object: T?) {
|
||||||
|
|
||||||
switch object {
|
switch object {
|
||||||
|
|
||||||
@@ -218,7 +218,7 @@ public struct Where: FetchClause, QueryClause, DeleteClause, Hashable {
|
|||||||
- parameter keyPath: the keyPath to compare with
|
- parameter keyPath: the keyPath to compare with
|
||||||
- parameter list: the sequence to check membership of
|
- parameter list: the sequence to check membership of
|
||||||
*/
|
*/
|
||||||
public init<S: Sequence>(_ keyPath: KeyPath, isMemberOf list: S) where S.Iterator.Element: QueryableAttributeType {
|
public init<S: Sequence>(_ keyPath: RawKeyPath, isMemberOf list: S) where S.Iterator.Element: QueryableAttributeType {
|
||||||
|
|
||||||
self.init(NSPredicate(format: "\(keyPath) IN %@", list.map({ $0.cs_toQueryableNativeType() }) as NSArray))
|
self.init(NSPredicate(format: "\(keyPath) IN %@", list.map({ $0.cs_toQueryableNativeType() }) as NSArray))
|
||||||
}
|
}
|
||||||
@@ -229,7 +229,7 @@ public struct Where: FetchClause, QueryClause, DeleteClause, Hashable {
|
|||||||
- parameter keyPath: the keyPath to compare with
|
- parameter keyPath: the keyPath to compare with
|
||||||
- parameter list: the sequence to check membership of
|
- parameter list: the sequence to check membership of
|
||||||
*/
|
*/
|
||||||
public init<S: Sequence>(_ keyPath: KeyPath, isMemberOf list: S) where S.Iterator.Element: DynamicObject {
|
public init<S: Sequence>(_ keyPath: RawKeyPath, isMemberOf list: S) where S.Iterator.Element: DynamicObject {
|
||||||
|
|
||||||
self.init(NSPredicate(format: "\(keyPath) IN %@", list.map({ $0.cs_id() }) as NSArray))
|
self.init(NSPredicate(format: "\(keyPath) IN %@", list.map({ $0.cs_id() }) as NSArray))
|
||||||
}
|
}
|
||||||
@@ -247,7 +247,7 @@ public struct Where: FetchClause, QueryClause, DeleteClause, Hashable {
|
|||||||
|
|
||||||
// MARK: FetchClause, QueryClause, DeleteClause
|
// MARK: FetchClause, QueryClause, DeleteClause
|
||||||
|
|
||||||
public func applyToFetchRequest<ResultType: NSFetchRequestResult>(_ fetchRequest: NSFetchRequest<ResultType>) {
|
public func applyToFetchRequest<ResultType>(_ fetchRequest: NSFetchRequest<ResultType>) {
|
||||||
|
|
||||||
if let predicate = fetchRequest.predicate, predicate != self.predicate {
|
if let predicate = fetchRequest.predicate, predicate != self.predicate {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user