mirror of
https://github.com/modo-studio/SugarRecord.git
synced 2024-10-26 14:40:37 +03:00
Migrate to Swift 3
This commit is contained in:
parent
e5dec67c38
commit
20afef64f5
2
Cartfile
2
Cartfile
@ -1 +1 @@
|
||||
github "realm/realm-cocoa" "v1.0.2"
|
||||
github "realm/realm-cocoa" "v1.1.0"
|
||||
|
@ -1 +1 @@
|
||||
github "realm/realm-cocoa" "v1.0.2"
|
||||
github "realm/realm-cocoa" "v1.1.0"
|
||||
|
@ -7,14 +7,14 @@
|
||||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
2334C4EF1D7DDB9000ACBC3A /* Realm.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2334C4ED1D7DDB9000ACBC3A /* Realm.framework */; };
|
||||
2334C4F01D7DDB9000ACBC3A /* RealmSwift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2334C4EE1D7DDB9000ACBC3A /* RealmSwift.framework */; };
|
||||
2334C4F31D7DDB9D00ACBC3A /* Realm.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2334C4F11D7DDB9D00ACBC3A /* Realm.framework */; };
|
||||
2334C4F41D7DDB9D00ACBC3A /* RealmSwift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2334C4F21D7DDB9D00ACBC3A /* RealmSwift.framework */; };
|
||||
2334C4F71D7DDBAB00ACBC3A /* Realm.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2334C4F51D7DDBAB00ACBC3A /* Realm.framework */; };
|
||||
2334C4F81D7DDBAB00ACBC3A /* RealmSwift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2334C4F61D7DDBAB00ACBC3A /* RealmSwift.framework */; };
|
||||
2334C4FB1D7DDBB600ACBC3A /* Realm.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2334C4F91D7DDBB600ACBC3A /* Realm.framework */; };
|
||||
2334C4FC1D7DDBB600ACBC3A /* RealmSwift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2334C4FA1D7DDBB600ACBC3A /* RealmSwift.framework */; };
|
||||
2356C0341D90547400488BFA /* Realm.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2356C0321D90547400488BFA /* Realm.framework */; };
|
||||
2356C0351D90547400488BFA /* RealmSwift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2356C0331D90547400488BFA /* RealmSwift.framework */; };
|
||||
2356C0381D9054CD00488BFA /* Realm.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2356C0361D9054CD00488BFA /* Realm.framework */; };
|
||||
2356C0391D9054CD00488BFA /* RealmSwift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2356C0371D9054CD00488BFA /* RealmSwift.framework */; };
|
||||
23E15CCC1D7DDE660073CC71 /* Request.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23E15CB81D7DDE660073CC71 /* Request.swift */; };
|
||||
23E15CCD1D7DDE660073CC71 /* Request.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23E15CB81D7DDE660073CC71 /* Request.swift */; };
|
||||
23E15CCE1D7DDE660073CC71 /* Request.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23E15CB81D7DDE660073CC71 /* Request.swift */; };
|
||||
@ -39,14 +39,14 @@
|
||||
23E15CE11D7DDE660073CC71 /* Storage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23E15CBA1D7DDE660073CC71 /* Storage.swift */; };
|
||||
23E15CE21D7DDE660073CC71 /* Storage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23E15CBA1D7DDE660073CC71 /* Storage.swift */; };
|
||||
23E15CE31D7DDE660073CC71 /* Storage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23E15CBA1D7DDE660073CC71 /* Storage.swift */; };
|
||||
23E15CE41D7DDE660073CC71 /* Error.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23E15CBC1D7DDE660073CC71 /* Error.swift */; };
|
||||
23E15CE51D7DDE660073CC71 /* Error.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23E15CBC1D7DDE660073CC71 /* Error.swift */; };
|
||||
23E15CE61D7DDE660073CC71 /* Error.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23E15CBC1D7DDE660073CC71 /* Error.swift */; };
|
||||
23E15CE71D7DDE660073CC71 /* Error.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23E15CBC1D7DDE660073CC71 /* Error.swift */; };
|
||||
23E15CE81D7DDE660073CC71 /* Error.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23E15CBC1D7DDE660073CC71 /* Error.swift */; };
|
||||
23E15CE91D7DDE660073CC71 /* Error.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23E15CBC1D7DDE660073CC71 /* Error.swift */; };
|
||||
23E15CEA1D7DDE660073CC71 /* Error.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23E15CBC1D7DDE660073CC71 /* Error.swift */; };
|
||||
23E15CEB1D7DDE660073CC71 /* Error.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23E15CBC1D7DDE660073CC71 /* Error.swift */; };
|
||||
23E15CE41D7DDE660073CC71 /* StorageError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23E15CBC1D7DDE660073CC71 /* StorageError.swift */; };
|
||||
23E15CE51D7DDE660073CC71 /* StorageError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23E15CBC1D7DDE660073CC71 /* StorageError.swift */; };
|
||||
23E15CE61D7DDE660073CC71 /* StorageError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23E15CBC1D7DDE660073CC71 /* StorageError.swift */; };
|
||||
23E15CE71D7DDE660073CC71 /* StorageError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23E15CBC1D7DDE660073CC71 /* StorageError.swift */; };
|
||||
23E15CE81D7DDE660073CC71 /* StorageError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23E15CBC1D7DDE660073CC71 /* StorageError.swift */; };
|
||||
23E15CE91D7DDE660073CC71 /* StorageError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23E15CBC1D7DDE660073CC71 /* StorageError.swift */; };
|
||||
23E15CEA1D7DDE660073CC71 /* StorageError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23E15CBC1D7DDE660073CC71 /* StorageError.swift */; };
|
||||
23E15CEB1D7DDE660073CC71 /* StorageError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23E15CBC1D7DDE660073CC71 /* StorageError.swift */; };
|
||||
23E15CEC1D7DDE660073CC71 /* RequestExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23E15CBE1D7DDE660073CC71 /* RequestExtension.swift */; };
|
||||
23E15CED1D7DDE660073CC71 /* RequestExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23E15CBE1D7DDE660073CC71 /* RequestExtension.swift */; };
|
||||
23E15CEE1D7DDE660073CC71 /* RequestExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23E15CBE1D7DDE660073CC71 /* RequestExtension.swift */; };
|
||||
@ -205,9 +205,6 @@
|
||||
23E15DA41D7DDE7B0073CC71 /* CoreDataDefaultStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23E15D6F1D7DDE7B0073CC71 /* CoreDataDefaultStorage.swift */; };
|
||||
23E15DA51D7DDE7B0073CC71 /* CoreDataiCloudStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23E15D701D7DDE7B0073CC71 /* CoreDataiCloudStorage.swift */; };
|
||||
23E15DA81D7DDE7B0073CC71 /* CoreDataiCloudStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23E15D701D7DDE7B0073CC71 /* CoreDataiCloudStorage.swift */; };
|
||||
23E15DAA1D7DE0ED0073CC71 /* CoreData.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 23E15DA91D7DE0ED0073CC71 /* CoreData.framework */; };
|
||||
23E15DAC1D7DE0F40073CC71 /* CoreData.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 23E15DAB1D7DE0F40073CC71 /* CoreData.framework */; };
|
||||
23E15DAE1D7DE0FA0073CC71 /* CoreData.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 23E15DAD1D7DE0FA0073CC71 /* CoreData.framework */; };
|
||||
23E15DB01D7DE1000073CC71 /* CoreData.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 23E15DAF1D7DE1000073CC71 /* CoreData.framework */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
@ -221,14 +218,14 @@
|
||||
2334C4D21D7DDA4F00ACBC3A /* SugarRecordRealm.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SugarRecordRealm.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
2334C4DC1D7DDA9900ACBC3A /* SugarRecordRealm.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SugarRecordRealm.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
2334C4E61D7DDAEF00ACBC3A /* SugarRecordRealm.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SugarRecordRealm.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
2334C4ED1D7DDB9000ACBC3A /* Realm.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Realm.framework; path = ../../Carthage/Build/watchOS/Realm.framework; sourceTree = "<group>"; };
|
||||
2334C4EE1D7DDB9000ACBC3A /* RealmSwift.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = RealmSwift.framework; path = ../../Carthage/Build/watchOS/RealmSwift.framework; sourceTree = "<group>"; };
|
||||
2334C4F11D7DDB9D00ACBC3A /* Realm.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Realm.framework; path = ../../Carthage/Build/Mac/Realm.framework; sourceTree = "<group>"; };
|
||||
2334C4F21D7DDB9D00ACBC3A /* RealmSwift.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = RealmSwift.framework; path = ../../Carthage/Build/Mac/RealmSwift.framework; sourceTree = "<group>"; };
|
||||
2334C4F51D7DDBAB00ACBC3A /* Realm.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Realm.framework; path = ../../Carthage/Build/iOS/Realm.framework; sourceTree = "<group>"; };
|
||||
2334C4F61D7DDBAB00ACBC3A /* RealmSwift.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = RealmSwift.framework; path = ../../Carthage/Build/iOS/RealmSwift.framework; sourceTree = "<group>"; };
|
||||
2334C4F91D7DDBB600ACBC3A /* Realm.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Realm.framework; path = ../../Carthage/Build/tvOS/Realm.framework; sourceTree = "<group>"; };
|
||||
2334C4FA1D7DDBB600ACBC3A /* RealmSwift.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = RealmSwift.framework; path = ../../Carthage/Build/tvOS/RealmSwift.framework; sourceTree = "<group>"; };
|
||||
2356C0321D90547400488BFA /* Realm.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Realm.framework; path = ../Carthage/Build/iOS/Realm.framework; sourceTree = "<group>"; };
|
||||
2356C0331D90547400488BFA /* RealmSwift.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = RealmSwift.framework; path = ../Carthage/Build/iOS/RealmSwift.framework; sourceTree = "<group>"; };
|
||||
2356C0361D9054CD00488BFA /* Realm.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Realm.framework; path = ../Carthage/Build/iOS/Realm.framework; sourceTree = "<group>"; };
|
||||
2356C0371D9054CD00488BFA /* RealmSwift.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = RealmSwift.framework; path = ../Carthage/Build/iOS/RealmSwift.framework; sourceTree = "<group>"; };
|
||||
23E15C601D7DDDF80073CC71 /* .gitignore */ = {isa = PBXFileReference; lastKnownFileType = text; path = .gitignore; sourceTree = "<group>"; };
|
||||
23E15C621D7DDDF80073CC71 /* Common.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Common.xcconfig; sourceTree = "<group>"; };
|
||||
23E15C641D7DDDF80073CC71 /* Debug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Debug.xcconfig; sourceTree = "<group>"; };
|
||||
@ -259,7 +256,7 @@
|
||||
23E15CB81D7DDE660073CC71 /* Request.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Request.swift; sourceTree = "<group>"; };
|
||||
23E15CB91D7DDE660073CC71 /* RequestObservable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RequestObservable.swift; sourceTree = "<group>"; };
|
||||
23E15CBA1D7DDE660073CC71 /* Storage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Storage.swift; sourceTree = "<group>"; };
|
||||
23E15CBC1D7DDE660073CC71 /* Error.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Error.swift; sourceTree = "<group>"; };
|
||||
23E15CBC1D7DDE660073CC71 /* StorageError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StorageError.swift; sourceTree = "<group>"; };
|
||||
23E15CBE1D7DDE660073CC71 /* RequestExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RequestExtension.swift; sourceTree = "<group>"; };
|
||||
23E15CC01D7DDE660073CC71 /* Logger.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Logger.swift; sourceTree = "<group>"; };
|
||||
23E15CC21D7DDE660073CC71 /* Context.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Context.swift; sourceTree = "<group>"; };
|
||||
@ -290,9 +287,6 @@
|
||||
23E15D6D1D7DDE7B0073CC71 /* NSManagedObjectMemoryContext.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSManagedObjectMemoryContext.swift; sourceTree = "<group>"; };
|
||||
23E15D6F1D7DDE7B0073CC71 /* CoreDataDefaultStorage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoreDataDefaultStorage.swift; sourceTree = "<group>"; };
|
||||
23E15D701D7DDE7B0073CC71 /* CoreDataiCloudStorage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoreDataiCloudStorage.swift; sourceTree = "<group>"; };
|
||||
23E15DA91D7DE0ED0073CC71 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.3.sdk/System/Library/Frameworks/CoreData.framework; sourceTree = DEVELOPER_DIR; };
|
||||
23E15DAB1D7DE0F40073CC71 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = Platforms/WatchOS.platform/Developer/SDKs/WatchOS2.2.sdk/System/Library/Frameworks/CoreData.framework; sourceTree = DEVELOPER_DIR; };
|
||||
23E15DAD1D7DE0FA0073CC71 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS9.2.sdk/System/Library/Frameworks/CoreData.framework; sourceTree = DEVELOPER_DIR; };
|
||||
23E15DAF1D7DE1000073CC71 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = System/Library/Frameworks/CoreData.framework; sourceTree = SDKROOT; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
@ -301,7 +295,6 @@
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
23E15DAA1D7DE0ED0073CC71 /* CoreData.framework in Frameworks */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@ -309,7 +302,6 @@
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
23E15DAC1D7DE0F40073CC71 /* CoreData.framework in Frameworks */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@ -317,7 +309,6 @@
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
23E15DAE1D7DE0FA0073CC71 /* CoreData.framework in Frameworks */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@ -333,8 +324,8 @@
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
2334C4F81D7DDBAB00ACBC3A /* RealmSwift.framework in Frameworks */,
|
||||
2334C4F71D7DDBAB00ACBC3A /* Realm.framework in Frameworks */,
|
||||
2356C0391D9054CD00488BFA /* RealmSwift.framework in Frameworks */,
|
||||
2356C0381D9054CD00488BFA /* Realm.framework in Frameworks */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@ -342,8 +333,8 @@
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
2334C4F01D7DDB9000ACBC3A /* RealmSwift.framework in Frameworks */,
|
||||
2334C4EF1D7DDB9000ACBC3A /* Realm.framework in Frameworks */,
|
||||
2356C0351D90547400488BFA /* RealmSwift.framework in Frameworks */,
|
||||
2356C0341D90547400488BFA /* Realm.framework in Frameworks */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@ -398,9 +389,6 @@
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
23E15DAF1D7DE1000073CC71 /* CoreData.framework */,
|
||||
23E15DAD1D7DE0FA0073CC71 /* CoreData.framework */,
|
||||
23E15DAB1D7DE0F40073CC71 /* CoreData.framework */,
|
||||
23E15DA91D7DE0ED0073CC71 /* CoreData.framework */,
|
||||
2334C4EC1D7DDB7C00ACBC3A /* watchOS */,
|
||||
2334C4EB1D7DDB7700ACBC3A /* macOS */,
|
||||
2334C4EA1D7DDB7100ACBC3A /* iOS */,
|
||||
@ -421,8 +409,8 @@
|
||||
2334C4EA1D7DDB7100ACBC3A /* iOS */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
2334C4F51D7DDBAB00ACBC3A /* Realm.framework */,
|
||||
2334C4F61D7DDBAB00ACBC3A /* RealmSwift.framework */,
|
||||
2356C0361D9054CD00488BFA /* Realm.framework */,
|
||||
2356C0371D9054CD00488BFA /* RealmSwift.framework */,
|
||||
);
|
||||
name = iOS;
|
||||
sourceTree = "<group>";
|
||||
@ -439,8 +427,8 @@
|
||||
2334C4EC1D7DDB7C00ACBC3A /* watchOS */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
2334C4ED1D7DDB9000ACBC3A /* Realm.framework */,
|
||||
2334C4EE1D7DDB9000ACBC3A /* RealmSwift.framework */,
|
||||
2356C0321D90547400488BFA /* Realm.framework */,
|
||||
2356C0331D90547400488BFA /* RealmSwift.framework */,
|
||||
);
|
||||
name = watchOS;
|
||||
sourceTree = "<group>";
|
||||
@ -574,7 +562,7 @@
|
||||
23E15CBB1D7DDE660073CC71 /* Errors */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
23E15CBC1D7DDE660073CC71 /* Error.swift */,
|
||||
23E15CBC1D7DDE660073CC71 /* StorageError.swift */,
|
||||
);
|
||||
path = Errors;
|
||||
sourceTree = "<group>";
|
||||
@ -926,7 +914,7 @@
|
||||
2334C4611D7DD8A500ACBC3A /* Project object */ = {
|
||||
isa = PBXProject;
|
||||
attributes = {
|
||||
LastUpgradeCheck = 0730;
|
||||
LastUpgradeCheck = 0800;
|
||||
ORGANIZATIONNAME = in.caramba.SugarRecord;
|
||||
TargetAttributes = {
|
||||
2334C4691D7DD8A500ACBC3A = {
|
||||
@ -1048,7 +1036,7 @@
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
23E15D9D1D7DDE7B0073CC71 /* NSManagedObjectMemoryContext.swift in Sources */,
|
||||
23E15CE51D7DDE660073CC71 /* Error.swift in Sources */,
|
||||
23E15CE51D7DDE660073CC71 /* StorageError.swift in Sources */,
|
||||
23E15D911D7DDE7B0073CC71 /* CoreDataErrors.swift in Sources */,
|
||||
23E15D7D1D7DDE7B0073CC71 /* CoreDataObservable.swift in Sources */,
|
||||
23E15D351D7DDE660073CC71 /* VersionProvider.swift in Sources */,
|
||||
@ -1083,7 +1071,7 @@
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
23E15D9E1D7DDE7B0073CC71 /* NSManagedObjectMemoryContext.swift in Sources */,
|
||||
23E15CE71D7DDE660073CC71 /* Error.swift in Sources */,
|
||||
23E15CE71D7DDE660073CC71 /* StorageError.swift in Sources */,
|
||||
23E15D921D7DDE7B0073CC71 /* CoreDataErrors.swift in Sources */,
|
||||
23E15D7E1D7DDE7B0073CC71 /* CoreDataObservable.swift in Sources */,
|
||||
23E15D371D7DDE660073CC71 /* VersionProvider.swift in Sources */,
|
||||
@ -1117,7 +1105,7 @@
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
23E15D9F1D7DDE7B0073CC71 /* NSManagedObjectMemoryContext.swift in Sources */,
|
||||
23E15CE91D7DDE660073CC71 /* Error.swift in Sources */,
|
||||
23E15CE91D7DDE660073CC71 /* StorageError.swift in Sources */,
|
||||
23E15D931D7DDE7B0073CC71 /* CoreDataErrors.swift in Sources */,
|
||||
23E15D7F1D7DDE7B0073CC71 /* CoreDataObservable.swift in Sources */,
|
||||
23E15D391D7DDE660073CC71 /* VersionProvider.swift in Sources */,
|
||||
@ -1151,7 +1139,7 @@
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
23E15DA01D7DDE7B0073CC71 /* NSManagedObjectMemoryContext.swift in Sources */,
|
||||
23E15CEB1D7DDE660073CC71 /* Error.swift in Sources */,
|
||||
23E15CEB1D7DDE660073CC71 /* StorageError.swift in Sources */,
|
||||
23E15D941D7DDE7B0073CC71 /* CoreDataErrors.swift in Sources */,
|
||||
23E15D801D7DDE7B0073CC71 /* CoreDataObservable.swift in Sources */,
|
||||
23E15D3B1D7DDE660073CC71 /* VersionProvider.swift in Sources */,
|
||||
@ -1185,7 +1173,7 @@
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
23E15CE41D7DDE660073CC71 /* Error.swift in Sources */,
|
||||
23E15CE41D7DDE660073CC71 /* StorageError.swift in Sources */,
|
||||
23E15D341D7DDE660073CC71 /* VersionProvider.swift in Sources */,
|
||||
23E15D521D7DDE700073CC71 /* RealmEntity.swift in Sources */,
|
||||
23E15CF41D7DDE660073CC71 /* Logger.swift in Sources */,
|
||||
@ -1212,7 +1200,7 @@
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
23E15CE61D7DDE660073CC71 /* Error.swift in Sources */,
|
||||
23E15CE61D7DDE660073CC71 /* StorageError.swift in Sources */,
|
||||
23E15D361D7DDE660073CC71 /* VersionProvider.swift in Sources */,
|
||||
23E15D531D7DDE700073CC71 /* RealmEntity.swift in Sources */,
|
||||
23E15CF61D7DDE660073CC71 /* Logger.swift in Sources */,
|
||||
@ -1239,7 +1227,7 @@
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
23E15CE81D7DDE660073CC71 /* Error.swift in Sources */,
|
||||
23E15CE81D7DDE660073CC71 /* StorageError.swift in Sources */,
|
||||
23E15D381D7DDE660073CC71 /* VersionProvider.swift in Sources */,
|
||||
23E15D541D7DDE700073CC71 /* RealmEntity.swift in Sources */,
|
||||
23E15CF81D7DDE660073CC71 /* Logger.swift in Sources */,
|
||||
@ -1266,7 +1254,7 @@
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
23E15CEA1D7DDE660073CC71 /* Error.swift in Sources */,
|
||||
23E15CEA1D7DDE660073CC71 /* StorageError.swift in Sources */,
|
||||
23E15D3A1D7DDE660073CC71 /* VersionProvider.swift in Sources */,
|
||||
23E15D551D7DDE700073CC71 /* RealmEntity.swift in Sources */,
|
||||
23E15CFA1D7DDE660073CC71 /* Logger.swift in Sources */,
|
||||
@ -1397,7 +1385,7 @@
|
||||
PRODUCT_BUNDLE_IDENTIFIER = in.caramba.SugarRecord;
|
||||
PRODUCT_NAME = SugarRecordCoreData;
|
||||
SKIP_INSTALL = YES;
|
||||
SWIFT_VERSION = 2.3;
|
||||
SWIFT_VERSION = 3.0;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
@ -1415,7 +1403,7 @@
|
||||
PRODUCT_BUNDLE_IDENTIFIER = in.caramba.SugarRecord;
|
||||
PRODUCT_NAME = SugarRecordCoreData;
|
||||
SKIP_INSTALL = YES;
|
||||
SWIFT_VERSION = 2.3;
|
||||
SWIFT_VERSION = 3.0;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
@ -1435,7 +1423,7 @@
|
||||
PRODUCT_NAME = SugarRecordCoreData;
|
||||
SDKROOT = watchos;
|
||||
SKIP_INSTALL = YES;
|
||||
SWIFT_VERSION = 2.3;
|
||||
SWIFT_VERSION = 3.0;
|
||||
TARGETED_DEVICE_FAMILY = 4;
|
||||
WATCHOS_DEPLOYMENT_TARGET = 2.2;
|
||||
};
|
||||
@ -1457,7 +1445,7 @@
|
||||
PRODUCT_NAME = SugarRecordCoreData;
|
||||
SDKROOT = watchos;
|
||||
SKIP_INSTALL = YES;
|
||||
SWIFT_VERSION = 2.3;
|
||||
SWIFT_VERSION = 3.0;
|
||||
TARGETED_DEVICE_FAMILY = 4;
|
||||
WATCHOS_DEPLOYMENT_TARGET = 2.2;
|
||||
};
|
||||
@ -1478,7 +1466,7 @@
|
||||
PRODUCT_NAME = SugarRecordCoreData;
|
||||
SDKROOT = appletvos;
|
||||
SKIP_INSTALL = YES;
|
||||
SWIFT_VERSION = 2.3;
|
||||
SWIFT_VERSION = 3.0;
|
||||
TARGETED_DEVICE_FAMILY = 3;
|
||||
TVOS_DEPLOYMENT_TARGET = 9.2;
|
||||
};
|
||||
@ -1499,7 +1487,7 @@
|
||||
PRODUCT_NAME = SugarRecordCoreData;
|
||||
SDKROOT = appletvos;
|
||||
SKIP_INSTALL = YES;
|
||||
SWIFT_VERSION = 2.3;
|
||||
SWIFT_VERSION = 3.0;
|
||||
TARGETED_DEVICE_FAMILY = 3;
|
||||
TVOS_DEPLOYMENT_TARGET = 9.2;
|
||||
};
|
||||
@ -1509,7 +1497,7 @@
|
||||
isa = XCBuildConfiguration;
|
||||
baseConfigurationReference = 23E15C751D7DDDF80073CC71 /* Mac-Framework.xcconfig */;
|
||||
buildSettings = {
|
||||
CODE_SIGN_IDENTITY = "-";
|
||||
CODE_SIGN_IDENTITY = "";
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
DEFINES_MODULE = YES;
|
||||
DYLIB_COMPATIBILITY_VERSION = 1;
|
||||
@ -1524,7 +1512,7 @@
|
||||
PRODUCT_NAME = SugarRecordCoreData;
|
||||
SDKROOT = macosx;
|
||||
SKIP_INSTALL = YES;
|
||||
SWIFT_VERSION = 2.3;
|
||||
SWIFT_VERSION = 3.0;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
@ -1532,7 +1520,7 @@
|
||||
isa = XCBuildConfiguration;
|
||||
baseConfigurationReference = 23E15C751D7DDDF80073CC71 /* Mac-Framework.xcconfig */;
|
||||
buildSettings = {
|
||||
CODE_SIGN_IDENTITY = "-";
|
||||
CODE_SIGN_IDENTITY = "";
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
DEFINES_MODULE = YES;
|
||||
DYLIB_COMPATIBILITY_VERSION = 1;
|
||||
@ -1547,7 +1535,7 @@
|
||||
PRODUCT_NAME = SugarRecordCoreData;
|
||||
SDKROOT = macosx;
|
||||
SKIP_INSTALL = YES;
|
||||
SWIFT_VERSION = 2.3;
|
||||
SWIFT_VERSION = 3.0;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
@ -1566,7 +1554,7 @@
|
||||
PRODUCT_BUNDLE_IDENTIFIER = in.caramba.SugarRecord;
|
||||
PRODUCT_NAME = SugarRecord;
|
||||
SKIP_INSTALL = YES;
|
||||
SWIFT_VERSION = 2.3;
|
||||
SWIFT_VERSION = 3.0;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
@ -1585,7 +1573,7 @@
|
||||
PRODUCT_BUNDLE_IDENTIFIER = in.caramba.SugarRecord;
|
||||
PRODUCT_NAME = SugarRecord;
|
||||
SKIP_INSTALL = YES;
|
||||
SWIFT_VERSION = 2.3;
|
||||
SWIFT_VERSION = 3.0;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
@ -1606,7 +1594,7 @@
|
||||
PRODUCT_NAME = SugarRecordRealm;
|
||||
SDKROOT = watchos;
|
||||
SKIP_INSTALL = YES;
|
||||
SWIFT_VERSION = 2.3;
|
||||
SWIFT_VERSION = 3.0;
|
||||
TARGETED_DEVICE_FAMILY = 4;
|
||||
WATCHOS_DEPLOYMENT_TARGET = 2.2;
|
||||
};
|
||||
@ -1629,7 +1617,7 @@
|
||||
PRODUCT_NAME = SugarRecordRealm;
|
||||
SDKROOT = watchos;
|
||||
SKIP_INSTALL = YES;
|
||||
SWIFT_VERSION = 2.3;
|
||||
SWIFT_VERSION = 3.0;
|
||||
TARGETED_DEVICE_FAMILY = 4;
|
||||
WATCHOS_DEPLOYMENT_TARGET = 2.2;
|
||||
};
|
||||
@ -1651,7 +1639,7 @@
|
||||
PRODUCT_NAME = SugarRecordRealm;
|
||||
SDKROOT = appletvos;
|
||||
SKIP_INSTALL = YES;
|
||||
SWIFT_VERSION = 2.3;
|
||||
SWIFT_VERSION = 3.0;
|
||||
TARGETED_DEVICE_FAMILY = 3;
|
||||
TVOS_DEPLOYMENT_TARGET = 9.2;
|
||||
};
|
||||
@ -1673,7 +1661,7 @@
|
||||
PRODUCT_NAME = SugarRecordRealm;
|
||||
SDKROOT = appletvos;
|
||||
SKIP_INSTALL = YES;
|
||||
SWIFT_VERSION = 2.3;
|
||||
SWIFT_VERSION = 3.0;
|
||||
TARGETED_DEVICE_FAMILY = 3;
|
||||
TVOS_DEPLOYMENT_TARGET = 9.2;
|
||||
};
|
||||
@ -1683,7 +1671,7 @@
|
||||
isa = XCBuildConfiguration;
|
||||
baseConfigurationReference = 23E15C751D7DDDF80073CC71 /* Mac-Framework.xcconfig */;
|
||||
buildSettings = {
|
||||
CODE_SIGN_IDENTITY = "-";
|
||||
CODE_SIGN_IDENTITY = "";
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
DEFINES_MODULE = YES;
|
||||
DYLIB_COMPATIBILITY_VERSION = 1;
|
||||
@ -1699,7 +1687,7 @@
|
||||
PRODUCT_NAME = SugarRecordRealm;
|
||||
SDKROOT = macosx;
|
||||
SKIP_INSTALL = YES;
|
||||
SWIFT_VERSION = 2.3;
|
||||
SWIFT_VERSION = 3.0;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
@ -1707,7 +1695,7 @@
|
||||
isa = XCBuildConfiguration;
|
||||
baseConfigurationReference = 23E15C751D7DDDF80073CC71 /* Mac-Framework.xcconfig */;
|
||||
buildSettings = {
|
||||
CODE_SIGN_IDENTITY = "-";
|
||||
CODE_SIGN_IDENTITY = "";
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
DEFINES_MODULE = YES;
|
||||
DYLIB_COMPATIBILITY_VERSION = 1;
|
||||
@ -1723,7 +1711,7 @@
|
||||
PRODUCT_NAME = SugarRecordRealm;
|
||||
SDKROOT = macosx;
|
||||
SKIP_INSTALL = YES;
|
||||
SWIFT_VERSION = 2.3;
|
||||
SWIFT_VERSION = 3.0;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0730"
|
||||
LastUpgradeVersion = "0800"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0730"
|
||||
LastUpgradeVersion = "0800"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0730"
|
||||
LastUpgradeVersion = "0800"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0730"
|
||||
LastUpgradeVersion = "0800"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0730"
|
||||
LastUpgradeVersion = "0800"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0730"
|
||||
LastUpgradeVersion = "0800"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0730"
|
||||
LastUpgradeVersion = "0800"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0730"
|
||||
LastUpgradeVersion = "0800"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0730"
|
||||
LastUpgradeVersion = "0800"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
|
@ -1,26 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>$(PRODUCT_NAME)</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>FMWK</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>$(CURRENT_PROJECT_VERSION)</string>
|
||||
<key>NSPrincipalClass</key>
|
||||
<string></string>
|
||||
</dict>
|
||||
</plist>
|
@ -1,19 +0,0 @@
|
||||
//
|
||||
// watchOS.h
|
||||
// watchOS
|
||||
//
|
||||
// Created by Pedro Pinera Buendia on 05/09/16.
|
||||
// Copyright © 2016 in.caramba.SugarRecord. All rights reserved.
|
||||
//
|
||||
|
||||
#import <WatchKit/WatchKit.h>
|
||||
|
||||
//! Project version number for watchOS.
|
||||
FOUNDATION_EXPORT double watchOSVersionNumber;
|
||||
|
||||
//! Project version string for watchOS.
|
||||
FOUNDATION_EXPORT const unsigned char watchOSVersionString[];
|
||||
|
||||
// In this header, you should import all the public headers of your framework using statements like #import <watchOS/PublicHeader.h>
|
||||
|
||||
|
@ -13,7 +13,7 @@ Pod::Spec.new do |s|
|
||||
s.osx.deployment_target = "10.10"
|
||||
|
||||
realm_dependencies = lambda do |spec|
|
||||
spec.dependency "RealmSwift", "~> 1.0.2"
|
||||
spec.dependency "RealmSwift", "~> 1.1"
|
||||
end
|
||||
|
||||
coredata_dependencies = lambda do |spec|
|
||||
|
@ -2,13 +2,13 @@ import Foundation
|
||||
import CoreData
|
||||
#if os(iOS) || os(tvOS) || os(watchOS)
|
||||
|
||||
public class CoreDataObservable<T: NSManagedObject where T:Equatable>: RequestObservable<T>, NSFetchedResultsControllerDelegate {
|
||||
public class CoreDataObservable<T: NSManagedObject>: RequestObservable<T>, NSFetchedResultsControllerDelegate where T:Equatable {
|
||||
|
||||
// MARK: - Attributes
|
||||
|
||||
internal let fetchRequest: NSFetchRequest
|
||||
internal var observer: (ObservableChange<T> -> Void)?
|
||||
internal let fetchedResultsController: NSFetchedResultsController
|
||||
internal let fetchRequest: NSFetchRequest<NSFetchRequestResult>
|
||||
internal var observer: ((ObservableChange<T>) -> Void)?
|
||||
internal let fetchedResultsController: NSFetchedResultsController<NSFetchRequestResult>
|
||||
private var batchChanges: [CoreDataChange<T>] = []
|
||||
|
||||
|
||||
@ -16,7 +16,7 @@ public class CoreDataObservable<T: NSManagedObject where T:Equatable>: RequestOb
|
||||
|
||||
internal init(request: Request<T>, context: NSManagedObjectContext) {
|
||||
|
||||
let fetchRequest: NSFetchRequest = NSFetchRequest(entityName: T.entityName)
|
||||
let fetchRequest: NSFetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: T.entityName)
|
||||
if let predicate = request.predicate {
|
||||
fetchRequest.predicate = predicate
|
||||
}
|
||||
@ -33,10 +33,10 @@ public class CoreDataObservable<T: NSManagedObject where T:Equatable>: RequestOb
|
||||
|
||||
// MARK: - Observable
|
||||
|
||||
public override func observe(closure: ObservableChange<T> -> Void) {
|
||||
public override func observe(_ closure: @escaping (ObservableChange<T>) -> Void) {
|
||||
assert(self.observer == nil, "Observable can be observed only once")
|
||||
let initial = try! self.fetchedResultsController.managedObjectContext.executeFetchRequest(self.fetchRequest) as! [T]
|
||||
closure(ObservableChange.Initial(initial))
|
||||
let initial = try! self.fetchedResultsController.managedObjectContext.fetch(self.fetchRequest) as! [T]
|
||||
closure(ObservableChange.initial(initial))
|
||||
self.observer = closure
|
||||
_ = try? self.fetchedResultsController.performFetch()
|
||||
}
|
||||
@ -51,27 +51,27 @@ public class CoreDataObservable<T: NSManagedObject where T:Equatable>: RequestOb
|
||||
|
||||
// MARK: - NSFetchedResultsControllerDelegate
|
||||
|
||||
public func controller(controller: NSFetchedResultsController, didChangeObject anObject: AnyObject, atIndexPath indexPath: NSIndexPath?, forChangeType type: NSFetchedResultsChangeType, newIndexPath: NSIndexPath?) {
|
||||
@nonobjc public func controller(controller: NSFetchedResultsController<NSFetchRequestResult>, didChangeObject anObject: AnyObject, atIndexPath indexPath: IndexPath?, forChangeType type: NSFetchedResultsChangeType, newIndexPath: IndexPath?) {
|
||||
switch type {
|
||||
case .Delete:
|
||||
self.batchChanges.append(.Delete(indexPath!.indexAtPosition(0), anObject as! T))
|
||||
case .Insert:
|
||||
self.batchChanges.append(.Insert(newIndexPath!.indexAtPosition(0), anObject as! T))
|
||||
case .Update:
|
||||
self.batchChanges.append(.Update(indexPath!.indexAtPosition(0), anObject as! T))
|
||||
case .delete:
|
||||
self.batchChanges.append(.Delete(indexPath![0], anObject as! T))
|
||||
case .insert:
|
||||
self.batchChanges.append(.Insert(newIndexPath![0], anObject as! T))
|
||||
case .update:
|
||||
self.batchChanges.append(.Update(indexPath![0], anObject as! T))
|
||||
default: break
|
||||
}
|
||||
}
|
||||
|
||||
public func controllerWillChangeContent(controller: NSFetchedResultsController) {
|
||||
public func controllerWillChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) {
|
||||
self.batchChanges = []
|
||||
}
|
||||
|
||||
public func controllerDidChangeContent(controller: NSFetchedResultsController) {
|
||||
public func controllerDidChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) {
|
||||
let deleted = self.batchChanges.filter { $0.isDeletion() }.map { $0.index() }
|
||||
let inserted = self.batchChanges.filter { $0.isInsertion() }.map { (index: $0.index(), element: $0.object()) }
|
||||
let updated = self.batchChanges.filter { $0.isUpdate() }.map { (index: $0.index(), element: $0.object()) }
|
||||
self.observer?(ObservableChange.Update(deletions: deleted, insertions: inserted, modifications: updated))
|
||||
self.observer?(ObservableChange.update(deletions: deleted, insertions: inserted, modifications: updated))
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,18 +4,18 @@ import CoreData
|
||||
public extension CoreData {
|
||||
|
||||
public enum ObjectModel {
|
||||
case Named(String, NSBundle)
|
||||
case Merged([NSBundle]?)
|
||||
case Named(String, Bundle)
|
||||
case Merged([Bundle]?)
|
||||
case URL(NSURL)
|
||||
|
||||
func model() -> NSManagedObjectModel? {
|
||||
switch self {
|
||||
case .Merged(let bundles):
|
||||
return NSManagedObjectModel.mergedModelFromBundles(bundles)
|
||||
return NSManagedObjectModel.mergedModel(from: bundles)
|
||||
case .Named(let name, let bundle):
|
||||
return NSManagedObjectModel(contentsOfURL: bundle.URLForResource(name, withExtension: "momd")!)
|
||||
return NSManagedObjectModel(contentsOf: bundle.url(forResource: name, withExtension: "momd")!)
|
||||
case .URL(let url):
|
||||
return NSManagedObjectModel(contentsOfURL: url)
|
||||
return NSManagedObjectModel(contentsOf: url as URL)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -7,23 +7,23 @@ public extension CoreData {
|
||||
case Default
|
||||
case Migration
|
||||
|
||||
func dict() -> [NSObject: AnyObject] {
|
||||
func dict() -> [String: AnyObject] {
|
||||
switch self {
|
||||
case .Default:
|
||||
var sqliteOptions: [String: String] = [String: String] ()
|
||||
sqliteOptions["journal_mode"] = "DELETE"
|
||||
var options: [NSObject: AnyObject] = [NSObject: AnyObject] ()
|
||||
options[NSMigratePersistentStoresAutomaticallyOption] = NSNumber(bool: true)
|
||||
options[NSInferMappingModelAutomaticallyOption] = NSNumber(bool: false)
|
||||
options[NSSQLitePragmasOption] = sqliteOptions
|
||||
var options: [String: AnyObject] = [String: AnyObject] ()
|
||||
options[NSMigratePersistentStoresAutomaticallyOption] = NSNumber(value: true)
|
||||
options[NSInferMappingModelAutomaticallyOption] = NSNumber(value: false)
|
||||
options[NSSQLitePragmasOption] = sqliteOptions as AnyObject?
|
||||
return options
|
||||
case .Migration:
|
||||
var sqliteOptions: [String: String] = [String: String] ()
|
||||
sqliteOptions["journal_mode"] = "DELETE"
|
||||
var options: [NSObject: AnyObject] = [NSObject: AnyObject] ()
|
||||
options[NSMigratePersistentStoresAutomaticallyOption] = NSNumber(bool: true)
|
||||
options[NSInferMappingModelAutomaticallyOption] = NSNumber(bool: true)
|
||||
options[NSSQLitePragmasOption] = sqliteOptions
|
||||
var options: [String: AnyObject] = [String: AnyObject] ()
|
||||
options[NSMigratePersistentStoresAutomaticallyOption] = NSNumber(value: true)
|
||||
options[NSInferMappingModelAutomaticallyOption] = NSNumber(value: true)
|
||||
options[NSSQLitePragmasOption] = sqliteOptions as AnyObject?
|
||||
return options
|
||||
}
|
||||
}
|
||||
|
@ -6,13 +6,13 @@ public extension CoreData {
|
||||
public enum Store {
|
||||
|
||||
case Named(String)
|
||||
case URL(NSURL)
|
||||
case URL(URL)
|
||||
|
||||
public func path() -> NSURL {
|
||||
public func path() -> URL {
|
||||
switch self {
|
||||
case .URL(let url): return url
|
||||
case .Named(let name):
|
||||
return NSURL(fileURLWithPath: documentsDirectory()).URLByAppendingPathComponent(name)!
|
||||
return Foundation.URL(fileURLWithPath: documentsDirectory()).appendingPathComponent(name)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,7 @@ import Foundation
|
||||
|
||||
public extension CoreData {
|
||||
|
||||
public enum Error: ErrorType {
|
||||
public enum CoreDataError: Error {
|
||||
case InvalidModel(CoreData.ObjectModel)
|
||||
case PersistenceStoreInitialization
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import CoreData
|
||||
extension NSManagedObject {
|
||||
|
||||
public class var entityName: String {
|
||||
return NSStringFromClass(self).componentsSeparatedByString(".").last!
|
||||
return NSStringFromClass(self).components(separatedBy: ".").last!
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,40 +6,40 @@ import CoreData
|
||||
|
||||
extension NSManagedObjectContext: Context {
|
||||
|
||||
public func fetch<T: Entity>(request: Request<T>) throws -> [T] {
|
||||
guard let entity = T.self as? NSManagedObject.Type else { throw Error.InvalidType }
|
||||
let fetchRequest: NSFetchRequest = NSFetchRequest(entityName: entity.entityName)
|
||||
public func fetch<T: Entity>(_ request: Request<T>) throws -> [T] {
|
||||
guard let entity = T.self as? NSManagedObject.Type else { throw StorageError.invalidType }
|
||||
let fetchRequest: NSFetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: entity.entityName)
|
||||
fetchRequest.predicate = request.predicate
|
||||
fetchRequest.sortDescriptors = request.sortDescriptor.map {[$0]}
|
||||
fetchRequest.fetchOffset = request.fetchOffset
|
||||
fetchRequest.fetchLimit = request.fetchLimit
|
||||
let results = try self.executeFetchRequest(fetchRequest)
|
||||
let results = try self.fetch(fetchRequest)
|
||||
let typedResults = results.map {$0 as! T}
|
||||
return typedResults
|
||||
}
|
||||
|
||||
public func insert<T: Entity>(entity: T) throws {}
|
||||
public func insert<T: Entity>(_ entity: T) throws {}
|
||||
|
||||
public func new<T: Entity>() throws -> T {
|
||||
guard let entity = T.self as? NSManagedObject.Type else { throw Error.InvalidType }
|
||||
let object = NSEntityDescription.insertNewObjectForEntityForName(entity.entityName, inManagedObjectContext: self)
|
||||
guard let entity = T.self as? NSManagedObject.Type else { throw StorageError.invalidType }
|
||||
let object = NSEntityDescription.insertNewObject(forEntityName: entity.entityName, into: self)
|
||||
if let inserted = object as? T {
|
||||
return inserted
|
||||
}
|
||||
else {
|
||||
throw Error.InvalidType
|
||||
throw StorageError.invalidType
|
||||
}
|
||||
}
|
||||
|
||||
public func remove<T: Entity>(objects: [T]) throws {
|
||||
public func remove<T: Entity>(_ objects: [T]) throws {
|
||||
for object in objects {
|
||||
guard let object = object as? NSManagedObject else { continue }
|
||||
self.deleteObject(object)
|
||||
self.delete(object)
|
||||
}
|
||||
}
|
||||
|
||||
public func removeAll() throws {
|
||||
throw Error.InvalidOperation("-removeAll not available in NSManagedObjectContext. Remove the store instead")
|
||||
throw StorageError.invalidOperation("-removeAll not available in NSManagedObjectContext. Remove the store instead")
|
||||
}
|
||||
|
||||
}
|
||||
@ -49,20 +49,20 @@ extension NSManagedObjectContext: Context {
|
||||
|
||||
extension NSManagedObjectContext {
|
||||
|
||||
func observe(inMainThread mainThread: Bool, saveNotification: (notification: NSNotification) -> Void) {
|
||||
let queue: NSOperationQueue = mainThread ? NSOperationQueue.mainQueue() : NSOperationQueue()
|
||||
NSNotificationCenter.defaultCenter().addObserverForName(NSManagedObjectContextDidSaveNotification, object: self, queue: queue, usingBlock: saveNotification)
|
||||
func observe(inMainThread mainThread: Bool, saveNotification: @escaping (_ notification: Notification) -> Void) {
|
||||
let queue: OperationQueue = mainThread ? OperationQueue.main : OperationQueue()
|
||||
NotificationCenter.default.addObserver(forName: NSNotification.Name.NSManagedObjectContextDidSave, object: self, queue: queue, using: saveNotification)
|
||||
}
|
||||
|
||||
func observeToGetPermanentIDsBeforeSaving() {
|
||||
NSNotificationCenter.defaultCenter().addObserverForName(NSManagedObjectContextWillSaveNotification, object: self, queue: nil, usingBlock: { [weak self] (notification) in
|
||||
NotificationCenter.default.addObserver(forName: NSNotification.Name.NSManagedObjectContextWillSave, object: self, queue: nil, using: { [weak self] (notification) in
|
||||
guard let s = self else {
|
||||
return
|
||||
}
|
||||
if s.insertedObjects.count == 0 {
|
||||
return
|
||||
}
|
||||
_ = try? s.obtainPermanentIDsForObjects(Array(s.insertedObjects))
|
||||
_ = try? s.obtainPermanentIDs(for: Array(s.insertedObjects))
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -20,40 +20,40 @@ public class CoreDataDefaultStorage: Storage {
|
||||
}
|
||||
}
|
||||
|
||||
public var type: StorageType = .CoreData
|
||||
public var type: StorageType = .coreData
|
||||
public var mainContext: Context!
|
||||
private var _saveContext: Context!
|
||||
public var saveContext: Context! {
|
||||
if let context = self._saveContext {
|
||||
return context
|
||||
}
|
||||
let _context = cdContext(withParent: .Context(self.rootSavingContext), concurrencyType: .PrivateQueueConcurrencyType, inMemory: false)
|
||||
let _context = cdContext(withParent: .Context(self.rootSavingContext), concurrencyType: .privateQueueConcurrencyType, inMemory: false)
|
||||
_context.observe(inMainThread: true) { [weak self] (notification) -> Void in
|
||||
(self?.mainContext as? NSManagedObjectContext)?.mergeChangesFromContextDidSaveNotification(notification)
|
||||
(self?.mainContext as? NSManagedObjectContext)?.mergeChanges(fromContextDidSave: notification as Notification)
|
||||
}
|
||||
self._saveContext = _context
|
||||
return _context
|
||||
}
|
||||
public var memoryContext: Context! {
|
||||
let _context = cdContext(withParent: .Context(self.rootSavingContext), concurrencyType: .PrivateQueueConcurrencyType, inMemory: true)
|
||||
let _context = cdContext(withParent: .Context(self.rootSavingContext), concurrencyType: .privateQueueConcurrencyType, inMemory: true)
|
||||
return _context
|
||||
}
|
||||
|
||||
public func operation<T>(operation: (context: Context, save: () -> Void) throws -> T) throws -> T {
|
||||
public func operation<T>(_ operation: @escaping (_ context: Context, _ save: @escaping () -> Void) throws -> T) throws -> T {
|
||||
let context: NSManagedObjectContext = self.saveContext as! NSManagedObjectContext
|
||||
var _error: ErrorType!
|
||||
var _error: Error!
|
||||
|
||||
var returnedObject: T!
|
||||
context.performBlockAndWait {
|
||||
context.performAndWait {
|
||||
do {
|
||||
returnedObject = try operation(context: context, save: { () -> Void in
|
||||
returnedObject = try operation(context, { () -> Void in
|
||||
do {
|
||||
try context.save()
|
||||
}
|
||||
catch {
|
||||
_error = error
|
||||
}
|
||||
self.rootSavingContext.performBlockAndWait({
|
||||
self.rootSavingContext.performAndWait({
|
||||
if self.rootSavingContext.hasChanges {
|
||||
do {
|
||||
try self.rootSavingContext.save()
|
||||
@ -76,9 +76,9 @@ public class CoreDataDefaultStorage: Storage {
|
||||
}
|
||||
|
||||
public func removeStore() throws {
|
||||
try NSFileManager.defaultManager().removeItemAtURL(store.path())
|
||||
_ = try? NSFileManager.defaultManager().removeItemAtPath("\(store.path().absoluteString)-shm")
|
||||
_ = try? NSFileManager.defaultManager().removeItemAtPath("\(store.path().absoluteString)-wal")
|
||||
try FileManager.default.removeItem(at: store.path() as URL)
|
||||
_ = try? FileManager.default.removeItem(atPath: "\(store.path().absoluteString)-shm")
|
||||
_ = try? FileManager.default.removeItem(atPath: "\(store.path().absoluteString)-wal")
|
||||
|
||||
}
|
||||
|
||||
@ -93,9 +93,9 @@ public class CoreDataDefaultStorage: Storage {
|
||||
self.store = store
|
||||
self.objectModel = model.model()!
|
||||
self.persistentStoreCoordinator = NSPersistentStoreCoordinator(managedObjectModel: objectModel)
|
||||
self.persistentStore = try cdInitializeStore(store, storeCoordinator: persistentStoreCoordinator, migrate: migrate)
|
||||
self.rootSavingContext = cdContext(withParent: .Coordinator(self.persistentStoreCoordinator), concurrencyType: .PrivateQueueConcurrencyType, inMemory: false)
|
||||
self.mainContext = cdContext(withParent: .Context(self.rootSavingContext), concurrencyType: .MainQueueConcurrencyType, inMemory: false)
|
||||
self.persistentStore = try cdInitializeStore(store: store, storeCoordinator: persistentStoreCoordinator, migrate: migrate)
|
||||
self.rootSavingContext = cdContext(withParent: .Coordinator(self.persistentStoreCoordinator), concurrencyType: .privateQueueConcurrencyType, inMemory: false)
|
||||
self.mainContext = cdContext(withParent: .Context(self.rootSavingContext), concurrencyType: .mainQueueConcurrencyType, inMemory: false)
|
||||
#if DEBUG
|
||||
versionController.check()
|
||||
#endif
|
||||
@ -105,7 +105,7 @@ public class CoreDataDefaultStorage: Storage {
|
||||
// MARK: - Public
|
||||
|
||||
#if os(iOS) || os(tvOS) || os(watchOS)
|
||||
public func observable<T: NSManagedObject where T:Equatable>(request: Request<T>) -> RequestObservable<T> {
|
||||
public func observable<T: NSManagedObject>(request: Request<T>) -> RequestObservable<T> where T:Equatable {
|
||||
return CoreDataObservable(request: request, context: self.mainContext as! NSManagedObjectContext)
|
||||
}
|
||||
#endif
|
||||
@ -126,7 +126,7 @@ internal func cdContext(withParent parent: CoreData.ContextParent?, concurrencyT
|
||||
if let parent = parent {
|
||||
switch parent {
|
||||
case .Context(let parentContext):
|
||||
context!.parentContext = parentContext
|
||||
context!.parent = parentContext
|
||||
case .Coordinator(let storeCoordinator):
|
||||
context!.persistentStoreCoordinator = storeCoordinator
|
||||
}
|
||||
@ -136,26 +136,25 @@ internal func cdContext(withParent parent: CoreData.ContextParent?, concurrencyT
|
||||
}
|
||||
|
||||
internal func cdInitializeStore(store: CoreData.Store, storeCoordinator: NSPersistentStoreCoordinator, migrate: Bool) throws -> NSPersistentStore {
|
||||
try cdCreateStoreParentPathIfNeeded(store)
|
||||
try cdCreateStoreParentPathIfNeeded(store: store)
|
||||
let options = migrate ? CoreData.Options.Migration : CoreData.Options.Default
|
||||
return try cdAddPersistentStore(store, storeCoordinator: storeCoordinator, options: options.dict())
|
||||
return try cdAddPersistentStore(store: store, storeCoordinator: storeCoordinator, options: options.dict())
|
||||
}
|
||||
|
||||
internal func cdCreateStoreParentPathIfNeeded(store: CoreData.Store) throws {
|
||||
if let databaseParentPath = store.path().URLByDeletingLastPathComponent {
|
||||
try NSFileManager.defaultManager().createDirectoryAtURL(databaseParentPath, withIntermediateDirectories: true, attributes: nil)
|
||||
}
|
||||
let databaseParentPath = store.path().deletingLastPathComponent()
|
||||
try FileManager.default.createDirectory(at: databaseParentPath, withIntermediateDirectories: true, attributes: nil)
|
||||
}
|
||||
|
||||
internal func cdAddPersistentStore(store: CoreData.Store, storeCoordinator: NSPersistentStoreCoordinator, options: [NSObject: AnyObject]) throws -> NSPersistentStore {
|
||||
internal func cdAddPersistentStore(store: CoreData.Store, storeCoordinator: NSPersistentStoreCoordinator, options: [String: AnyObject]) throws -> NSPersistentStore {
|
||||
|
||||
var addStore: ((store: CoreData.Store, storeCoordinator: NSPersistentStoreCoordinator, options: [NSObject: AnyObject], cleanAndRetryIfMigrationFails: Bool) throws -> NSPersistentStore)?
|
||||
addStore = { (store: CoreData.Store, coordinator: NSPersistentStoreCoordinator, options: [NSObject: AnyObject], retry: Bool) throws -> NSPersistentStore in
|
||||
var addStore: ((_ store: CoreData.Store, _ storeCoordinator: NSPersistentStoreCoordinator, _ options: [String: AnyObject], _ cleanAndRetryIfMigrationFails: Bool) throws -> NSPersistentStore)?
|
||||
addStore = { (store: CoreData.Store, coordinator: NSPersistentStoreCoordinator, options: [String: AnyObject], retry: Bool) throws -> NSPersistentStore in
|
||||
var persistentStore: NSPersistentStore?
|
||||
var error: NSError?
|
||||
coordinator.performBlockAndWait({ () -> Void in
|
||||
coordinator.performAndWait({ () -> Void in
|
||||
do {
|
||||
persistentStore = try storeCoordinator.addPersistentStoreWithType(NSSQLiteStoreType, configuration: nil, URL: store.path(), options: options)
|
||||
persistentStore = try storeCoordinator.addPersistentStore(ofType: NSSQLiteStoreType, configurationName: nil, at: store.path() as URL, options: options)
|
||||
}
|
||||
catch let _error as NSError {
|
||||
error = _error
|
||||
@ -165,7 +164,7 @@ internal func cdAddPersistentStore(store: CoreData.Store, storeCoordinator: NSPe
|
||||
let isMigrationError = error.code == NSPersistentStoreIncompatibleVersionHashError || error.code == NSMigrationMissingSourceModelError
|
||||
if isMigrationError && retry {
|
||||
_ = try? cdCleanStoreFilesAfterFailedMigration(store: store)
|
||||
try addStore!(store: store, storeCoordinator: coordinator, options: options, cleanAndRetryIfMigrationFails: false)
|
||||
return try addStore!(store, coordinator, options, false)
|
||||
}
|
||||
else {
|
||||
throw error
|
||||
@ -174,16 +173,16 @@ internal func cdAddPersistentStore(store: CoreData.Store, storeCoordinator: NSPe
|
||||
else if let persistentStore = persistentStore {
|
||||
return persistentStore
|
||||
}
|
||||
throw CoreData.Error.PersistenceStoreInitialization
|
||||
throw CoreData.CoreDataError.PersistenceStoreInitialization
|
||||
}
|
||||
return try addStore!(store: store, storeCoordinator: storeCoordinator, options: options, cleanAndRetryIfMigrationFails: true)
|
||||
return try addStore!(store, storeCoordinator, options, true)
|
||||
}
|
||||
|
||||
internal func cdCleanStoreFilesAfterFailedMigration(store store: CoreData.Store) throws {
|
||||
let rawUrl: String = store.path().absoluteString!
|
||||
let shmSidecar: NSURL = NSURL(string: rawUrl.stringByAppendingString("-shm"))!
|
||||
let walSidecar: NSURL = NSURL(string: rawUrl.stringByAppendingString("-wal"))!
|
||||
try NSFileManager.defaultManager().removeItemAtURL(store.path())
|
||||
try NSFileManager.defaultManager().removeItemAtURL(shmSidecar)
|
||||
try NSFileManager.defaultManager().removeItemAtURL(walSidecar)
|
||||
internal func cdCleanStoreFilesAfterFailedMigration(store: CoreData.Store) throws {
|
||||
let rawUrl: String = store.path().absoluteString
|
||||
let shmSidecar: NSURL = NSURL(string: rawUrl.appending("-shm"))!
|
||||
let walSidecar: NSURL = NSURL(string: rawUrl.appending("-wal"))!
|
||||
try FileManager.default.removeItem(at: store.path() as URL)
|
||||
try FileManager.default.removeItem(at: shmSidecar as URL)
|
||||
try FileManager.default.removeItem(at: walSidecar as URL)
|
||||
}
|
||||
|
@ -19,15 +19,15 @@ public class CoreDataiCloudStorage: Storage {
|
||||
return "CoreDataiCloudStorage"
|
||||
}
|
||||
}
|
||||
public var type: StorageType = .CoreData
|
||||
public var type: StorageType = .coreData
|
||||
|
||||
public var mainContext: Context!
|
||||
|
||||
public var saveContext: Context! {
|
||||
get {
|
||||
let context = cdContext(withParent: .Context(self.rootSavingContext), concurrencyType: .PrivateQueueConcurrencyType, inMemory: false)
|
||||
let context = cdContext(withParent: .Context(self.rootSavingContext), concurrencyType: .privateQueueConcurrencyType, inMemory: false)
|
||||
context.observe(inMainThread: true) { [weak self] (notification) -> Void in
|
||||
(self?.mainContext as? NSManagedObjectContext)?.mergeChangesFromContextDidSaveNotification(notification)
|
||||
(self?.mainContext as? NSManagedObjectContext)?.mergeChanges(fromContextDidSave: notification as Notification)
|
||||
}
|
||||
return context
|
||||
}
|
||||
@ -35,20 +35,20 @@ public class CoreDataiCloudStorage: Storage {
|
||||
|
||||
public var memoryContext: Context! {
|
||||
get {
|
||||
let context = cdContext(withParent: .Context(self.rootSavingContext), concurrencyType: .PrivateQueueConcurrencyType, inMemory: true)
|
||||
let context = cdContext(withParent: .Context(self.rootSavingContext), concurrencyType: .privateQueueConcurrencyType, inMemory: true)
|
||||
return context
|
||||
}
|
||||
}
|
||||
|
||||
public func operation<T>(operation: (context: Context, save: () -> Void) throws -> T) throws -> T {
|
||||
public func operation<T>(_ operation: @escaping (_ context: Context, _ save: @escaping () -> Void) throws -> T) throws -> T {
|
||||
let context: NSManagedObjectContext = (self.saveContext as? NSManagedObjectContext)!
|
||||
var _error: ErrorType!
|
||||
var _error: Error!
|
||||
|
||||
var returnedObject: T!
|
||||
|
||||
context.performBlockAndWait {
|
||||
context.performAndWait {
|
||||
do {
|
||||
returnedObject = try operation(context: context, save: { () -> Void in
|
||||
returnedObject = try operation(context, { () -> Void in
|
||||
do {
|
||||
try context.save()
|
||||
}
|
||||
@ -56,7 +56,7 @@ public class CoreDataiCloudStorage: Storage {
|
||||
_error = error
|
||||
}
|
||||
if self.rootSavingContext.hasChanges {
|
||||
self.rootSavingContext.performBlockAndWait {
|
||||
self.rootSavingContext.performAndWait {
|
||||
do {
|
||||
try self.rootSavingContext.save()
|
||||
}
|
||||
@ -79,7 +79,7 @@ public class CoreDataiCloudStorage: Storage {
|
||||
}
|
||||
|
||||
public func removeStore() throws {
|
||||
try NSFileManager.defaultManager().removeItemAtURL(store.path())
|
||||
try FileManager.default.removeItem(at: store.path() as URL)
|
||||
}
|
||||
|
||||
|
||||
@ -92,9 +92,11 @@ public class CoreDataiCloudStorage: Storage {
|
||||
internal init(model: CoreData.ObjectModel, iCloud: ICloudConfig, versionController: VersionController) throws {
|
||||
self.objectModel = model.model()!
|
||||
self.persistentStoreCoordinator = NSPersistentStoreCoordinator(managedObjectModel: objectModel)
|
||||
(self.store, self.persistentStore) = try! cdiCloudInitializeStore(storeCoordinator: persistentStoreCoordinator, iCloud: iCloud)
|
||||
self.rootSavingContext = cdContext(withParent: .Coordinator(self.persistentStoreCoordinator), concurrencyType: .PrivateQueueConcurrencyType, inMemory: false)
|
||||
self.mainContext = cdContext(withParent: .Context(self.rootSavingContext), concurrencyType: .MainQueueConcurrencyType, inMemory: false)
|
||||
let result = try! cdiCloudInitializeStore(storeCoordinator: persistentStoreCoordinator, iCloud: iCloud)
|
||||
self.store = result.0
|
||||
self.persistentStore = result.1
|
||||
self.rootSavingContext = cdContext(withParent: .Coordinator(self.persistentStoreCoordinator), concurrencyType: .privateQueueConcurrencyType, inMemory: false)
|
||||
self.mainContext = cdContext(withParent: .Context(self.rootSavingContext), concurrencyType: .mainQueueConcurrencyType, inMemory: false)
|
||||
self.observeiCloudChangesInCoordinator()
|
||||
#if DEBUG
|
||||
versionController.check()
|
||||
@ -106,7 +108,7 @@ public class CoreDataiCloudStorage: Storage {
|
||||
|
||||
#if os(iOS) || os(tvOS) || os(watchOS)
|
||||
|
||||
public func observable<T: NSManagedObject where T:Equatable>(request: Request<T>) -> RequestObservable<T> {
|
||||
public func observable<T: NSManagedObject>(request: Request<T>) -> RequestObservable<T> where T:Equatable {
|
||||
return CoreDataObservable(request: request, context: self.mainContext as! NSManagedObjectContext)
|
||||
}
|
||||
|
||||
@ -115,24 +117,24 @@ public class CoreDataiCloudStorage: Storage {
|
||||
// MARK: - Private
|
||||
|
||||
private func observeiCloudChangesInCoordinator() {
|
||||
NSNotificationCenter
|
||||
.defaultCenter()
|
||||
.addObserverForName(NSPersistentStoreDidImportUbiquitousContentChangesNotification, object: self.persistentStoreCoordinator, queue: nil) { [weak self] (notification) -> Void in
|
||||
self?.rootSavingContext.performBlock {
|
||||
self?.rootSavingContext.mergeChangesFromContextDidSaveNotification(notification)
|
||||
NotificationCenter
|
||||
.default
|
||||
.addObserver(forName: NSNotification.Name.NSPersistentStoreDidImportUbiquitousContentChanges, object: self.persistentStoreCoordinator, queue: nil) { [weak self] (notification) -> Void in
|
||||
self?.rootSavingContext.perform {
|
||||
self?.rootSavingContext.mergeChanges(fromContextDidSave: notification)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal func cdiCloudInitializeStore(storeCoordinator storeCoordinator: NSPersistentStoreCoordinator, iCloud: ICloudConfig) throws -> (CoreData.Store, NSPersistentStore!) {
|
||||
let storeURL = NSFileManager.defaultManager()
|
||||
.URLForUbiquityContainerIdentifier(iCloud.ubiquitousContainerIdentifier)!
|
||||
.URLByAppendingPathComponent(iCloud.ubiquitousContentURL)
|
||||
internal func cdiCloudInitializeStore(storeCoordinator: NSPersistentStoreCoordinator, iCloud: ICloudConfig) throws -> (CoreData.Store, NSPersistentStore?) {
|
||||
let storeURL = FileManager.default
|
||||
.url(forUbiquityContainerIdentifier: iCloud.ubiquitousContainerIdentifier)!
|
||||
.appendingPathComponent(iCloud.ubiquitousContentURL)
|
||||
var options = CoreData.Options.Migration.dict()
|
||||
options[NSPersistentStoreUbiquitousContentURLKey] = storeURL
|
||||
options[NSPersistentStoreUbiquitousContentNameKey] = iCloud.ubiquitousContentName
|
||||
let store = CoreData.Store.URL(storeURL!)
|
||||
return try (store, cdAddPersistentStore(store, storeCoordinator: storeCoordinator, options: options))
|
||||
options[NSPersistentStoreUbiquitousContentURLKey] = storeURL as AnyObject?
|
||||
options[NSPersistentStoreUbiquitousContentNameKey] = iCloud.ubiquitousContentName as AnyObject?
|
||||
let store = CoreData.Store.URL(storeURL)
|
||||
return try (store, cdAddPersistentStore(store: store, storeCoordinator: storeCoordinator, options: options))
|
||||
}
|
||||
|
@ -28,39 +28,39 @@ public struct Request<T: Entity>: Equatable {
|
||||
return try context!.fetch(self)
|
||||
}
|
||||
|
||||
public func fetch(requestable: Requestable) throws -> [T] {
|
||||
public func fetch(_ requestable: Requestable) throws -> [T] {
|
||||
return try requestable.requestContext().fetch(self)
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Public Builder Methods
|
||||
|
||||
public func filteredWith(predicate predicate: NSPredicate) -> Request<T> {
|
||||
public func filteredWith(predicate: NSPredicate) -> Request<T> {
|
||||
return self
|
||||
.request(withPredicate: predicate)
|
||||
}
|
||||
|
||||
public func filteredWith(key: String, equalTo value: String) -> Request<T> {
|
||||
public func filteredWith(_ key: String, equalTo value: String) -> Request<T> {
|
||||
return self
|
||||
.request(withPredicate: NSPredicate(format: "\(key) == %@", value))
|
||||
}
|
||||
|
||||
public func sortedWith(sortDescriptor sortDescriptor: NSSortDescriptor) -> Request<T> {
|
||||
public func sortedWith(sortDescriptor: NSSortDescriptor) -> Request<T> {
|
||||
return self
|
||||
.request(withSortDescriptor: sortDescriptor)
|
||||
}
|
||||
|
||||
public func sortedWith(key: String?, ascending: Bool, comparator cmptr: NSComparator) -> Request<T> {
|
||||
public func sortedWith(_ key: String?, ascending: Bool, comparator cmptr: @escaping Comparator) -> Request<T> {
|
||||
return self
|
||||
.request(withSortDescriptor: NSSortDescriptor(key: key, ascending: ascending, comparator: cmptr))
|
||||
}
|
||||
|
||||
public func sortedWith(key: String?, ascending: Bool) -> Request<T> {
|
||||
public func sortedWith(_ key: String?, ascending: Bool) -> Request<T> {
|
||||
return self
|
||||
.request(withSortDescriptor: NSSortDescriptor(key: key, ascending: ascending))
|
||||
}
|
||||
|
||||
public func sortedWith(key: String?, ascending: Bool, selector: Selector) -> Request<T> {
|
||||
public func sortedWith(_ key: String?, ascending: Bool, selector: Selector) -> Request<T> {
|
||||
return self
|
||||
.request(withSortDescriptor: NSSortDescriptor(key: key, ascending: ascending, selector: selector))
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
import Foundation
|
||||
|
||||
public enum ObservableChange<T> {
|
||||
case Initial([T])
|
||||
case Update(deletions: [Int], insertions: [(index: Int, element: T)], modifications: [(index: Int, element: T)])
|
||||
case Error(NSError)
|
||||
case initial([T])
|
||||
case update(deletions: [Int], insertions: [(index: Int, element: T)], modifications: [(index: Int, element: T)])
|
||||
case error(Error)
|
||||
}
|
||||
|
||||
public class RequestObservable<T: Entity>: NSObject {
|
||||
open class RequestObservable<T: Entity>: NSObject {
|
||||
|
||||
// MARK: - Attributes
|
||||
|
||||
@ -22,7 +22,7 @@ public class RequestObservable<T: Entity>: NSObject {
|
||||
|
||||
// MARK: - Public
|
||||
|
||||
public func observe(closure: ObservableChange<T> -> Void) {
|
||||
open func observe(_ closure: @escaping (ObservableChange<T>) -> Void) {
|
||||
assertionFailure("The observe method must be overriden")
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,11 @@
|
||||
import Foundation
|
||||
|
||||
public enum StorageType {
|
||||
case CoreData
|
||||
case Realm
|
||||
case coreData
|
||||
case realm
|
||||
}
|
||||
|
||||
typealias StorageOperation = ((context: Context, save: () -> Void) throws -> Void) throws -> Void
|
||||
typealias StorageOperation = ((_ context: Context, _ save: () -> Void) throws -> Void) throws -> Void
|
||||
|
||||
public protocol Storage: CustomStringConvertible, Requestable {
|
||||
|
||||
@ -14,8 +14,8 @@ public protocol Storage: CustomStringConvertible, Requestable {
|
||||
var saveContext: Context! { get }
|
||||
var memoryContext: Context! { get }
|
||||
func removeStore() throws
|
||||
func operation<T>(operation: (context: Context, save: () -> Void) throws -> T) throws -> T
|
||||
func fetch<T: Entity>(request: Request<T>) throws -> [T]
|
||||
func operation<T>(_ operation: @escaping (_ context: Context, _ save: @escaping () -> Void) throws -> T) throws -> T
|
||||
func fetch<T: Entity>(_ request: Request<T>) throws -> [T]
|
||||
|
||||
}
|
||||
|
||||
@ -23,7 +23,7 @@ public protocol Storage: CustomStringConvertible, Requestable {
|
||||
|
||||
public extension Storage {
|
||||
|
||||
func fetch<T: Entity>(request: Request<T>) throws -> [T] {
|
||||
func fetch<T: Entity>(_ request: Request<T>) throws -> [T] {
|
||||
return try self.mainContext.fetch(request)
|
||||
}
|
||||
|
||||
|
@ -1,10 +0,0 @@
|
||||
import Foundation
|
||||
|
||||
public enum Error: ErrorType {
|
||||
case WriteError
|
||||
case InvalidType
|
||||
case FetchError(ErrorType)
|
||||
case Store(ErrorType)
|
||||
case InvalidOperation(String)
|
||||
case Unknown
|
||||
}
|
12
SugarRecord/Source/Foundation/Errors/StorageError.swift
Normal file
12
SugarRecord/Source/Foundation/Errors/StorageError.swift
Normal file
@ -0,0 +1,12 @@
|
||||
import Foundation
|
||||
|
||||
public indirect enum StorageError: Error {
|
||||
|
||||
case writeError
|
||||
case invalidType
|
||||
case fetchError(Error)
|
||||
case store(Error)
|
||||
case invalidOperation(String)
|
||||
case unknown
|
||||
|
||||
}
|
@ -4,8 +4,8 @@ internal class Logger {
|
||||
|
||||
// MARK: - Internal
|
||||
|
||||
internal func log(message: String) {
|
||||
internal func log(_ message: String) {
|
||||
print("🍬 SugarRecord: \(message)")
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -2,12 +2,12 @@ import Foundation
|
||||
|
||||
public protocol Context: Requestable {
|
||||
|
||||
func fetch<T: Entity>(request: Request<T>) throws -> [T]
|
||||
func insert<T: Entity>(entity: T) throws
|
||||
func fetch<T: Entity>(_ request: Request<T>) throws -> [T]
|
||||
func insert<T: Entity>(_ entity: T) throws
|
||||
func new<T: Entity>() throws -> T
|
||||
func create<T: Entity>() throws -> T
|
||||
func remove<T: Entity>(objects: [T]) throws
|
||||
func remove<T: Entity>(object: T) throws
|
||||
func remove<T: Entity>(_ objects: [T]) throws
|
||||
func remove<T: Entity>(_ object: T) throws
|
||||
func removeAll() throws
|
||||
}
|
||||
|
||||
@ -22,7 +22,7 @@ public extension Context {
|
||||
return instance
|
||||
}
|
||||
|
||||
public func remove<T: Entity>(object: T) throws {
|
||||
public func remove<T: Entity>(_ object: T) throws {
|
||||
return try self.remove([object])
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,7 @@ import Foundation
|
||||
public protocol Requestable {
|
||||
|
||||
func requestContext() -> Context
|
||||
func request<T>(model: T.Type) -> Request<T>
|
||||
func request<T>(_ model: T.Type) -> Request<T>
|
||||
|
||||
}
|
||||
|
||||
@ -13,7 +13,7 @@ public extension Requestable where Self: Context {
|
||||
return self
|
||||
}
|
||||
|
||||
func request<T>(model: T.Type) -> Request<T> {
|
||||
func request<T>(_ model: T.Type) -> Request<T> {
|
||||
return Request<T>(self)
|
||||
}
|
||||
|
||||
@ -25,7 +25,7 @@ public extension Requestable where Self:Storage {
|
||||
return self.mainContext
|
||||
}
|
||||
|
||||
func request<T>(model: T.Type) -> Request<T> {
|
||||
func request<T>(_ model: T.Type) -> Request<T> {
|
||||
return Request<T>(self.mainContext)
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import Foundation
|
||||
|
||||
func documentsDirectory() -> String {
|
||||
let paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
|
||||
let paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
|
||||
return paths[0]
|
||||
}
|
||||
|
@ -4,8 +4,8 @@ internal class VersionController {
|
||||
|
||||
// MARK: - Attributes
|
||||
|
||||
private let provider: VersionProvider
|
||||
private let logger: Logger
|
||||
fileprivate let provider: VersionProvider
|
||||
fileprivate let logger: Logger
|
||||
|
||||
|
||||
// MARK: - Init
|
||||
|
@ -10,18 +10,18 @@ internal class VersionProvider: NSObject {
|
||||
// MARK: - Internal
|
||||
|
||||
internal func framework() -> String! {
|
||||
if let version = NSBundle(forClass: VersionProvider.classForCoder()).objectForInfoDictionaryKey("CFBundleShortVersionString") as? String {
|
||||
if let version = Bundle(for: VersionProvider.classForCoder()).object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String {
|
||||
return version
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
internal func github(completion: String -> Void) {
|
||||
let request: NSURLRequest = NSURLRequest(URL: NSURL(string: VersionProvider.apiReleasesUrl)!)
|
||||
NSURLSession(configuration: NSURLSessionConfiguration.defaultSessionConfiguration()).dataTaskWithRequest(request, completionHandler: { (data, response, error) in
|
||||
internal func github(_ completion: @escaping (String) -> Void) {
|
||||
let request: URLRequest = URLRequest(url: URL(string: VersionProvider.apiReleasesUrl)!)
|
||||
URLSession(configuration: URLSessionConfiguration.default).dataTask(with: request, completionHandler: { (data, response, error) in
|
||||
if let data = data {
|
||||
let json: AnyObject? = try? NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.AllowFragments)
|
||||
if let array = json as? [[String: AnyObject]], lastVersion = array.first, versionTag: String = lastVersion["tag_name"] as? String {
|
||||
let json: AnyObject? = try! JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.allowFragments) as AnyObject?
|
||||
if let array = json as? [[String: AnyObject]], let lastVersion = array.first, let versionTag: String = lastVersion["tag_name"] as? String {
|
||||
completion(versionTag)
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import Foundation
|
||||
import RealmSwift
|
||||
|
||||
public class RealmObservable<T: Object>: RequestObservable<T> {
|
||||
open class RealmObservable<T: Object>: RequestObservable<T> {
|
||||
|
||||
// MARK: - Attributes
|
||||
|
||||
@ -19,14 +19,14 @@ public class RealmObservable<T: Object>: RequestObservable<T> {
|
||||
|
||||
// MARK: - Observable
|
||||
|
||||
public override func observe(closure: ObservableChange<T> -> Void) {
|
||||
open override func observe(_ closure: @escaping (ObservableChange<T>) -> Void) {
|
||||
assert(self.notificationToken == nil, "Observable can be observed only once")
|
||||
var realmObjects = self.realm.objects(T)
|
||||
var realmObjects = self.realm.objects(T.self)
|
||||
if let predicate = self.request.predicate {
|
||||
realmObjects = realmObjects.filter(predicate)
|
||||
}
|
||||
if let sortDescriptor = self.request.sortDescriptor {
|
||||
realmObjects = realmObjects.sorted(sortDescriptor.key!, ascending: sortDescriptor.ascending)
|
||||
realmObjects = realmObjects.sorted(byProperty: sortDescriptor.key!, ascending: sortDescriptor.ascending)
|
||||
}
|
||||
self.notificationToken = realmObjects.addNotificationBlock { (changes: RealmCollectionChange<Results<T>>) in
|
||||
closure(self.map(changes))
|
||||
@ -40,17 +40,17 @@ public class RealmObservable<T: Object>: RequestObservable<T> {
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private func map(realmChange: RealmCollectionChange<Results<T>>) -> ObservableChange<T> {
|
||||
fileprivate func map(_ realmChange: RealmCollectionChange<Results<T>>) -> ObservableChange<T> {
|
||||
switch realmChange {
|
||||
case .Error(let error):
|
||||
return ObservableChange.Error(error)
|
||||
case .Initial(let initial):
|
||||
return ObservableChange.Initial(initial.toArray())
|
||||
case .Update(let objects, let deletions, let insertions, let modifications):
|
||||
case .error(let error):
|
||||
return ObservableChange.error(error)
|
||||
case .initial(let initial):
|
||||
return ObservableChange.initial(initial.toArray())
|
||||
case .update(let objects, let deletions, let insertions, let modifications):
|
||||
let deletions = deletions.map { $0 }
|
||||
let insertions = insertions.map { (index: $0, element: objects[$0]) }
|
||||
let modifications = modifications.map { (index: $0, element: objects[$0]) }
|
||||
return ObservableChange.Update(deletions: deletions, insertions: insertions, modifications: modifications)
|
||||
return ObservableChange.update(deletions: deletions, insertions: insertions, modifications: modifications)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,29 +3,29 @@ import RealmSwift
|
||||
|
||||
extension Realm: Context {
|
||||
|
||||
public func fetch<T: Entity>(request: Request<T>) throws -> [T] {
|
||||
guard let entity = T.self as? Object.Type else { throw Error.InvalidType }
|
||||
public func fetch<T: Entity>(_ request: Request<T>) throws -> [T] {
|
||||
guard let entity = T.self as? Object.Type else { throw StorageError.invalidType }
|
||||
var results = self.objects(entity.self)
|
||||
if let predicate = request.predicate {
|
||||
results = results.filter(predicate)
|
||||
}
|
||||
if let sortDescriptor = request.sortDescriptor, key = sortDescriptor.key {
|
||||
results = results.sorted(key, ascending: sortDescriptor.ascending)
|
||||
if let sortDescriptor = request.sortDescriptor, let key = sortDescriptor.key {
|
||||
results = results.sorted(byProperty: key, ascending: sortDescriptor.ascending)
|
||||
}
|
||||
return results.toArray().map { $0 as Any as! T }
|
||||
}
|
||||
|
||||
public func insert<T: Entity>(entity: T) throws {
|
||||
guard let _ = T.self as? Object.Type else { throw Error.InvalidType }
|
||||
public func insert<T: Entity>(_ entity: T) throws {
|
||||
guard let _ = T.self as? Object.Type else { throw StorageError.invalidType }
|
||||
self.add(entity as! Object, update: false)
|
||||
}
|
||||
|
||||
public func new<T: Entity>() throws -> T {
|
||||
guard let entity = T.self as? Object.Type else { throw Error.InvalidType }
|
||||
guard let entity = T.self as? Object.Type else { throw StorageError.invalidType }
|
||||
return entity.init() as! T
|
||||
}
|
||||
|
||||
public func remove<T: Entity>(objects: [T]) throws {
|
||||
public func remove<T: Entity>(_ objects: [T]) throws {
|
||||
let objectsToDelete = objects
|
||||
.map { $0.realm }
|
||||
.filter { $0 != nil }
|
||||
|
@ -1,11 +1,11 @@
|
||||
import Foundation
|
||||
import RealmSwift
|
||||
|
||||
public class RealmDefaultStorage: Storage {
|
||||
open class RealmDefaultStorage: Storage {
|
||||
|
||||
// MARK: - Attributes
|
||||
|
||||
private let configuration: Realm.Configuration?
|
||||
fileprivate let configuration: Realm.Configuration?
|
||||
|
||||
|
||||
/// MARK: - Init
|
||||
@ -24,11 +24,11 @@ public class RealmDefaultStorage: Storage {
|
||||
|
||||
// MARK: - Storage
|
||||
|
||||
public var description: String { return "RealmDefaultStorage" }
|
||||
open var description: String { return "RealmDefaultStorage" }
|
||||
|
||||
public var type: StorageType { return .Realm }
|
||||
open var type: StorageType { return .realm }
|
||||
|
||||
public var mainContext: Context! {
|
||||
open var mainContext: Context! {
|
||||
if let configuration = self.configuration {
|
||||
return try? Realm(configuration: configuration)
|
||||
}
|
||||
@ -37,7 +37,7 @@ public class RealmDefaultStorage: Storage {
|
||||
}
|
||||
}
|
||||
|
||||
public var saveContext: Context! {
|
||||
open var saveContext: Context! {
|
||||
if let configuration = self.configuration {
|
||||
return try? Realm(configuration: configuration)
|
||||
}
|
||||
@ -46,25 +46,25 @@ public class RealmDefaultStorage: Storage {
|
||||
}
|
||||
}
|
||||
|
||||
public var memoryContext: Context! {
|
||||
open var memoryContext: Context! {
|
||||
return try? Realm(configuration: Realm.Configuration(inMemoryIdentifier: "MemoryRealm"))
|
||||
}
|
||||
|
||||
public func removeStore() throws {
|
||||
open func removeStore() throws {
|
||||
if let url = try Realm().configuration.fileURL {
|
||||
try NSFileManager.defaultManager().removeItemAtURL(url)
|
||||
try FileManager.default.removeItem(at: url)
|
||||
}
|
||||
}
|
||||
|
||||
public func operation<T>(operation: (context: Context, save: () -> Void) throws -> T) throws -> T {
|
||||
open func operation<T>(_ operation: @escaping (_ context: Context, _ save: @escaping () -> Void) throws -> T) throws -> T {
|
||||
let context: Realm = self.saveContext as! Realm
|
||||
context.beginWrite()
|
||||
var save: Bool = false
|
||||
var _error: ErrorType!
|
||||
var _error: Swift.Error!
|
||||
|
||||
var returnedObject: T!
|
||||
do {
|
||||
returnedObject = try operation(context: context, save: { () -> Void in
|
||||
returnedObject = try operation(context, { () -> Void in
|
||||
defer {
|
||||
save = true
|
||||
}
|
||||
@ -91,7 +91,7 @@ public class RealmDefaultStorage: Storage {
|
||||
|
||||
}
|
||||
|
||||
public func observable<T: Object>(request: Request<T>) -> RequestObservable<T> {
|
||||
open func observable<T: Object>(_ request: Request<T>) -> RequestObservable<T> {
|
||||
return RealmObservable(request: request, realm: self.mainContext as! Realm)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user