mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-04-25 10:08:31 +02:00
custom error handling, logging, and asserting
This commit is contained in:
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -1,6 +1,3 @@
|
|||||||
[submodule "Libraries/JEToolkit"]
|
|
||||||
path = Libraries/JEToolkit
|
|
||||||
url = git@github.com:JohnEstropia/JEToolkit.git
|
|
||||||
[submodule "Libraries/GCDKit"]
|
[submodule "Libraries/GCDKit"]
|
||||||
path = Libraries/GCDKit
|
path = Libraries/GCDKit
|
||||||
url = git@github.com:JohnEstropia/GCDKit.git
|
url = git@github.com:JohnEstropia/GCDKit.git
|
||||||
|
|||||||
@@ -21,7 +21,8 @@
|
|||||||
B5D39A0219FD00C9000E91BB /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B5D39A0119FD00C9000E91BB /* Foundation.framework */; };
|
B5D39A0219FD00C9000E91BB /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B5D39A0119FD00C9000E91BB /* Foundation.framework */; };
|
||||||
B5D39A0419FD00DE000E91BB /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B5D39A0319FD00DE000E91BB /* UIKit.framework */; };
|
B5D39A0419FD00DE000E91BB /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B5D39A0319FD00DE000E91BB /* UIKit.framework */; };
|
||||||
B5D8080E1A3471A500A44484 /* GCDKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B5D808021A34715700A44484 /* GCDKit.framework */; };
|
B5D8080E1A3471A500A44484 /* GCDKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B5D808021A34715700A44484 /* GCDKit.framework */; };
|
||||||
B5D8080F1A3471A900A44484 /* JEToolkit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B5D808081A34715700A44484 /* JEToolkit.framework */; };
|
B5D808161A34947300A44484 /* NotificationObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5D808151A34947300A44484 /* NotificationObserver.swift */; };
|
||||||
|
B5D8081A1A3495BD00A44484 /* NSObject+HardcoreData.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5D808191A3495BD00A44484 /* NSObject+HardcoreData.swift */; };
|
||||||
B5E209E01A0726460089C9D4 /* NSManagedObject+HardcoreData.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E209DF1A0726460089C9D4 /* NSManagedObject+HardcoreData.swift */; };
|
B5E209E01A0726460089C9D4 /* NSManagedObject+HardcoreData.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E209DF1A0726460089C9D4 /* NSManagedObject+HardcoreData.swift */; };
|
||||||
B5F539901A17A6FC00EC763B /* QueryDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5F5398F1A17A6FC00EC763B /* QueryDescriptor.swift */; };
|
B5F539901A17A6FC00EC763B /* QueryDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5F5398F1A17A6FC00EC763B /* QueryDescriptor.swift */; };
|
||||||
/* End PBXBuildFile section */
|
/* End PBXBuildFile section */
|
||||||
@@ -41,20 +42,6 @@
|
|||||||
remoteGlobalIDString = 2FBBCAD619A9FE610070E4AB;
|
remoteGlobalIDString = 2FBBCAD619A9FE610070E4AB;
|
||||||
remoteInfo = GCDKitTests;
|
remoteInfo = GCDKitTests;
|
||||||
};
|
};
|
||||||
B5D808071A34715700A44484 /* PBXContainerItemProxy */ = {
|
|
||||||
isa = PBXContainerItemProxy;
|
|
||||||
containerPortal = B5D8074E1A34715700A44484 /* JEToolkit.xcodeproj */;
|
|
||||||
proxyType = 2;
|
|
||||||
remoteGlobalIDString = 2F74E6F519DFCC7A00FB0C88;
|
|
||||||
remoteInfo = JEToolkit;
|
|
||||||
};
|
|
||||||
B5D808091A34715700A44484 /* PBXContainerItemProxy */ = {
|
|
||||||
isa = PBXContainerItemProxy;
|
|
||||||
containerPortal = B5D8074E1A34715700A44484 /* JEToolkit.xcodeproj */;
|
|
||||||
proxyType = 2;
|
|
||||||
remoteGlobalIDString = 2F74E70019DFCC7A00FB0C88;
|
|
||||||
remoteInfo = JEToolkitTests;
|
|
||||||
};
|
|
||||||
/* End PBXContainerItemProxy section */
|
/* End PBXContainerItemProxy section */
|
||||||
|
|
||||||
/* Begin PBXFileReference section */
|
/* Begin PBXFileReference section */
|
||||||
@@ -76,7 +63,8 @@
|
|||||||
B5D39A0119FD00C9000E91BB /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
|
B5D39A0119FD00C9000E91BB /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
|
||||||
B5D39A0319FD00DE000E91BB /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
|
B5D39A0319FD00DE000E91BB /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
|
||||||
B5D806C51A34715700A44484 /* GCDKit.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; path = GCDKit.xcodeproj; sourceTree = "<group>"; };
|
B5D806C51A34715700A44484 /* GCDKit.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; path = GCDKit.xcodeproj; sourceTree = "<group>"; };
|
||||||
B5D8074E1A34715700A44484 /* JEToolkit.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; path = JEToolkit.xcodeproj; sourceTree = "<group>"; };
|
B5D808151A34947300A44484 /* NotificationObserver.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NotificationObserver.swift; sourceTree = "<group>"; };
|
||||||
|
B5D808191A3495BD00A44484 /* NSObject+HardcoreData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSObject+HardcoreData.swift"; sourceTree = "<group>"; };
|
||||||
B5E209DF1A0726460089C9D4 /* NSManagedObject+HardcoreData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSManagedObject+HardcoreData.swift"; sourceTree = "<group>"; };
|
B5E209DF1A0726460089C9D4 /* NSManagedObject+HardcoreData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSManagedObject+HardcoreData.swift"; sourceTree = "<group>"; };
|
||||||
B5F3D98419F3EB8E009690A6 /* LICENSE */ = {isa = PBXFileReference; lastKnownFileType = text; path = LICENSE; sourceTree = "<group>"; };
|
B5F3D98419F3EB8E009690A6 /* LICENSE */ = {isa = PBXFileReference; lastKnownFileType = text; path = LICENSE; sourceTree = "<group>"; };
|
||||||
B5F5398F1A17A6FC00EC763B /* QueryDescriptor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QueryDescriptor.swift; sourceTree = "<group>"; };
|
B5F5398F1A17A6FC00EC763B /* QueryDescriptor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QueryDescriptor.swift; sourceTree = "<group>"; };
|
||||||
@@ -87,7 +75,6 @@
|
|||||||
isa = PBXFrameworksBuildPhase;
|
isa = PBXFrameworksBuildPhase;
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
B5D8080F1A3471A900A44484 /* JEToolkit.framework in Frameworks */,
|
|
||||||
B5D8080E1A3471A500A44484 /* GCDKit.framework in Frameworks */,
|
B5D8080E1A3471A500A44484 /* GCDKit.framework in Frameworks */,
|
||||||
B5D39A0419FD00DE000E91BB /* UIKit.framework in Frameworks */,
|
B5D39A0419FD00DE000E91BB /* UIKit.framework in Frameworks */,
|
||||||
B5D39A0219FD00C9000E91BB /* Foundation.framework in Frameworks */,
|
B5D39A0219FD00C9000E91BB /* Foundation.framework in Frameworks */,
|
||||||
@@ -139,6 +126,7 @@
|
|||||||
B5F5398F1A17A6FC00EC763B /* QueryDescriptor.swift */,
|
B5F5398F1A17A6FC00EC763B /* QueryDescriptor.swift */,
|
||||||
B5D1E22919FA9E63003B2874 /* PersistentStoreResult.swift */,
|
B5D1E22919FA9E63003B2874 /* PersistentStoreResult.swift */,
|
||||||
B5CFD36D1A0775F000B7885F /* SaveResult.swift */,
|
B5CFD36D1A0775F000B7885F /* SaveResult.swift */,
|
||||||
|
B5D808141A34945A00A44484 /* Internal */,
|
||||||
2F03A53319C5C6DA005002A5 /* Supporting Files */,
|
2F03A53319C5C6DA005002A5 /* Supporting Files */,
|
||||||
);
|
);
|
||||||
path = HardcoreData;
|
path = HardcoreData;
|
||||||
@@ -184,7 +172,6 @@
|
|||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
B5D806BC1A34715700A44484 /* GCDKit */,
|
B5D806BC1A34715700A44484 /* GCDKit */,
|
||||||
B5D806CD1A34715700A44484 /* JEToolkit */,
|
|
||||||
);
|
);
|
||||||
path = Libraries;
|
path = Libraries;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@@ -206,21 +193,13 @@
|
|||||||
name = Products;
|
name = Products;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
};
|
};
|
||||||
B5D806CD1A34715700A44484 /* JEToolkit */ = {
|
B5D808141A34945A00A44484 /* Internal */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
B5D8074E1A34715700A44484 /* JEToolkit.xcodeproj */,
|
B5D808151A34947300A44484 /* NotificationObserver.swift */,
|
||||||
|
B5D808191A3495BD00A44484 /* NSObject+HardcoreData.swift */,
|
||||||
);
|
);
|
||||||
path = JEToolkit;
|
name = Internal;
|
||||||
sourceTree = "<group>";
|
|
||||||
};
|
|
||||||
B5D8074F1A34715700A44484 /* Products */ = {
|
|
||||||
isa = PBXGroup;
|
|
||||||
children = (
|
|
||||||
B5D808081A34715700A44484 /* JEToolkit.framework */,
|
|
||||||
B5D8080A1A34715700A44484 /* JEToolkitTests.xctest */,
|
|
||||||
);
|
|
||||||
name = Products;
|
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
};
|
};
|
||||||
/* End PBXGroup section */
|
/* End PBXGroup section */
|
||||||
@@ -305,10 +284,6 @@
|
|||||||
ProductGroup = B5D806C61A34715700A44484 /* Products */;
|
ProductGroup = B5D806C61A34715700A44484 /* Products */;
|
||||||
ProjectRef = B5D806C51A34715700A44484 /* GCDKit.xcodeproj */;
|
ProjectRef = B5D806C51A34715700A44484 /* GCDKit.xcodeproj */;
|
||||||
},
|
},
|
||||||
{
|
|
||||||
ProductGroup = B5D8074F1A34715700A44484 /* Products */;
|
|
||||||
ProjectRef = B5D8074E1A34715700A44484 /* JEToolkit.xcodeproj */;
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
projectRoot = "";
|
projectRoot = "";
|
||||||
targets = (
|
targets = (
|
||||||
@@ -333,20 +308,6 @@
|
|||||||
remoteRef = B5D808031A34715700A44484 /* PBXContainerItemProxy */;
|
remoteRef = B5D808031A34715700A44484 /* PBXContainerItemProxy */;
|
||||||
sourceTree = BUILT_PRODUCTS_DIR;
|
sourceTree = BUILT_PRODUCTS_DIR;
|
||||||
};
|
};
|
||||||
B5D808081A34715700A44484 /* JEToolkit.framework */ = {
|
|
||||||
isa = PBXReferenceProxy;
|
|
||||||
fileType = wrapper.framework;
|
|
||||||
path = JEToolkit.framework;
|
|
||||||
remoteRef = B5D808071A34715700A44484 /* PBXContainerItemProxy */;
|
|
||||||
sourceTree = BUILT_PRODUCTS_DIR;
|
|
||||||
};
|
|
||||||
B5D8080A1A34715700A44484 /* JEToolkitTests.xctest */ = {
|
|
||||||
isa = PBXReferenceProxy;
|
|
||||||
fileType = wrapper.cfbundle;
|
|
||||||
path = JEToolkitTests.xctest;
|
|
||||||
remoteRef = B5D808091A34715700A44484 /* PBXContainerItemProxy */;
|
|
||||||
sourceTree = BUILT_PRODUCTS_DIR;
|
|
||||||
};
|
|
||||||
/* End PBXReferenceProxy section */
|
/* End PBXReferenceProxy section */
|
||||||
|
|
||||||
/* Begin PBXResourcesBuildPhase section */
|
/* Begin PBXResourcesBuildPhase section */
|
||||||
@@ -378,9 +339,11 @@
|
|||||||
B5D1E22C19FA9FBC003B2874 /* NSError+HardcoreData.swift in Sources */,
|
B5D1E22C19FA9FBC003B2874 /* NSError+HardcoreData.swift in Sources */,
|
||||||
B5CFF23E19FD1D1C00D6DFC4 /* NSManagedObjectContext+HardcoreData.swift in Sources */,
|
B5CFF23E19FD1D1C00D6DFC4 /* NSManagedObjectContext+HardcoreData.swift in Sources */,
|
||||||
2F291E2719C6D3CF007AF63F /* HardcoreData.swift in Sources */,
|
2F291E2719C6D3CF007AF63F /* HardcoreData.swift in Sources */,
|
||||||
|
B5D8081A1A3495BD00A44484 /* NSObject+HardcoreData.swift in Sources */,
|
||||||
B5E209E01A0726460089C9D4 /* NSManagedObject+HardcoreData.swift in Sources */,
|
B5E209E01A0726460089C9D4 /* NSManagedObject+HardcoreData.swift in Sources */,
|
||||||
B5D1E22A19FA9E63003B2874 /* PersistentStoreResult.swift in Sources */,
|
B5D1E22A19FA9E63003B2874 /* PersistentStoreResult.swift in Sources */,
|
||||||
B5D399F119FC818E000E91BB /* DataStack.swift in Sources */,
|
B5D399F119FC818E000E91BB /* DataStack.swift in Sources */,
|
||||||
|
B5D808161A34947300A44484 /* NotificationObserver.swift in Sources */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
};
|
};
|
||||||
@@ -491,15 +454,12 @@
|
|||||||
EMBEDDED_CONTENT_CONTAINS_SWIFT = YES;
|
EMBEDDED_CONTENT_CONTAINS_SWIFT = YES;
|
||||||
FRAMEWORK_SEARCH_PATHS = (
|
FRAMEWORK_SEARCH_PATHS = (
|
||||||
"$(inherited)",
|
"$(inherited)",
|
||||||
/Users/johnestropia/Documents/XCode,
|
|
||||||
"Projects/JEToolkit/build/Debug-iphoneos",
|
|
||||||
"$(USER_LIBRARY_DIR)/Developer/Xcode/DerivedData/PhotoSearch-dzwflhandxxuvngptapvysfpcwdx/Build/Products/Debug-iphoneos",
|
"$(USER_LIBRARY_DIR)/Developer/Xcode/DerivedData/PhotoSearch-dzwflhandxxuvngptapvysfpcwdx/Build/Products/Debug-iphoneos",
|
||||||
/Users/johnestropia/Documents/XCode,
|
|
||||||
"Projects/JEToolkit/build/Debug-iphoneos",
|
|
||||||
);
|
);
|
||||||
INFOPLIST_FILE = HardcoreData/Info.plist;
|
INFOPLIST_FILE = HardcoreData/Info.plist;
|
||||||
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
|
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
|
||||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||||
|
OTHER_SWIFT_FLAGS = "-D DEBUG";
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
SKIP_INSTALL = YES;
|
SKIP_INSTALL = YES;
|
||||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
||||||
@@ -517,15 +477,12 @@
|
|||||||
EMBEDDED_CONTENT_CONTAINS_SWIFT = YES;
|
EMBEDDED_CONTENT_CONTAINS_SWIFT = YES;
|
||||||
FRAMEWORK_SEARCH_PATHS = (
|
FRAMEWORK_SEARCH_PATHS = (
|
||||||
"$(inherited)",
|
"$(inherited)",
|
||||||
/Users/johnestropia/Documents/XCode,
|
|
||||||
"Projects/JEToolkit/build/Debug-iphoneos",
|
|
||||||
"$(USER_LIBRARY_DIR)/Developer/Xcode/DerivedData/PhotoSearch-dzwflhandxxuvngptapvysfpcwdx/Build/Products/Debug-iphoneos",
|
"$(USER_LIBRARY_DIR)/Developer/Xcode/DerivedData/PhotoSearch-dzwflhandxxuvngptapvysfpcwdx/Build/Products/Debug-iphoneos",
|
||||||
/Users/johnestropia/Documents/XCode,
|
|
||||||
"Projects/JEToolkit/build/Debug-iphoneos",
|
|
||||||
);
|
);
|
||||||
INFOPLIST_FILE = HardcoreData/Info.plist;
|
INFOPLIST_FILE = HardcoreData/Info.plist;
|
||||||
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
|
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
|
||||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||||
|
OTHER_SWIFT_FLAGS = "";
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
SKIP_INSTALL = YES;
|
SKIP_INSTALL = YES;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -27,6 +27,12 @@ import Foundation
|
|||||||
import CoreData
|
import CoreData
|
||||||
import GCDKit
|
import GCDKit
|
||||||
|
|
||||||
|
|
||||||
|
private let applicationSupportDirectory = NSFileManager.defaultManager().URLsForDirectory(.ApplicationSupportDirectory, inDomains: .UserDomainMask).first as NSURL
|
||||||
|
|
||||||
|
private let applicationName = NSBundle.mainBundle().objectForInfoDictionaryKey("CFBundleName") as String
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The DataStack encapsulates the data model for the Core Data stack. Each DataStack can have multiple data stores, usually specified as a "Configuration" in the model editor. Behind the scenes, the DataStack manages its own NSPersistentStoreCoordinator, a root NSManagedObjectContext for disk saves, and a shared NSManagedObjectContext acting as a model interface for NSManagedObjects.
|
The DataStack encapsulates the data model for the Core Data stack. Each DataStack can have multiple data stores, usually specified as a "Configuration" in the model editor. Behind the scenes, the DataStack manages its own NSPersistentStoreCoordinator, a root NSManagedObjectContext for disk saves, and a shared NSManagedObjectContext acting as a model interface for NSManagedObjects.
|
||||||
*/
|
*/
|
||||||
@@ -101,14 +107,14 @@ public class DataStack: NSObject {
|
|||||||
|
|
||||||
HardcoreData.handleError(
|
HardcoreData.handleError(
|
||||||
error,
|
error,
|
||||||
message: "Failed to add in-memory NSPersistentStore.")
|
"Failed to add in-memory NSPersistentStore.")
|
||||||
return PersistentStoreResult(error)
|
return PersistentStoreResult(error)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
HardcoreData.handleError(
|
HardcoreData.handleError(
|
||||||
NSError(hardcoreDataErrorCode: .UnknownError),
|
NSError(hardcoreDataErrorCode: .UnknownError),
|
||||||
message: "Failed to add in-memory NSPersistentStore.")
|
"Failed to add in-memory NSPersistentStore.")
|
||||||
}
|
}
|
||||||
return PersistentStoreResult(.UnknownError)
|
return PersistentStoreResult(.UnknownError)
|
||||||
}
|
}
|
||||||
@@ -125,7 +131,7 @@ public class DataStack: NSObject {
|
|||||||
public func addSQLiteStore(fileName: String, configuration: String? = nil, automigrating: Bool = true, resetStoreOnMigrationFailure: Bool = false) -> PersistentStoreResult {
|
public func addSQLiteStore(fileName: String, configuration: String? = nil, automigrating: Bool = true, resetStoreOnMigrationFailure: Bool = false) -> PersistentStoreResult {
|
||||||
|
|
||||||
return self.addSQLiteStore(
|
return self.addSQLiteStore(
|
||||||
fileURL: NSURL.applicationSupportDirectory().URLByAppendingPathComponent(fileName, isDirectory: false),
|
fileURL: applicationSupportDirectory.URLByAppendingPathComponent(fileName, isDirectory: false),
|
||||||
configuration: configuration,
|
configuration: configuration,
|
||||||
automigrating: automigrating,
|
automigrating: automigrating,
|
||||||
resetStoreOnMigrationFailure: resetStoreOnMigrationFailure)
|
resetStoreOnMigrationFailure: resetStoreOnMigrationFailure)
|
||||||
@@ -140,7 +146,7 @@ public class DataStack: NSObject {
|
|||||||
:param: resetStoreOnMigrationFailure Set to true to delete the store on migration failure; or set to false to throw exceptions on failure instead. Typically should only be set to true when debugging, or if the persistent store can be recreated easily. If not specified, defaults to false.
|
:param: resetStoreOnMigrationFailure Set to true to delete the store on migration failure; or set to false to throw exceptions on failure instead. Typically should only be set to true when debugging, or if the persistent store can be recreated easily. If not specified, defaults to false.
|
||||||
:returns: a PersistentStoreResult indicating success or failure.
|
:returns: a PersistentStoreResult indicating success or failure.
|
||||||
*/
|
*/
|
||||||
public func addSQLiteStore(fileURL: NSURL = NSURL.applicationSupportDirectory().URLByAppendingPathComponent(NSString.applicationName(), isDirectory: true).URLByAppendingPathExtension("sqlite"), configuration: String? = nil, automigrating: Bool = true, resetStoreOnMigrationFailure: Bool = false) -> PersistentStoreResult {
|
public func addSQLiteStore(fileURL: NSURL = applicationSupportDirectory.URLByAppendingPathComponent(applicationName, isDirectory: true).URLByAppendingPathExtension("sqlite"), configuration: String? = nil, automigrating: Bool = true, resetStoreOnMigrationFailure: Bool = false) -> PersistentStoreResult {
|
||||||
|
|
||||||
let coordinator = self.coordinator;
|
let coordinator = self.coordinator;
|
||||||
if let store = coordinator.persistentStoreForURL(fileURL) {
|
if let store = coordinator.persistentStoreForURL(fileURL) {
|
||||||
@@ -155,7 +161,7 @@ public class DataStack: NSObject {
|
|||||||
|
|
||||||
HardcoreData.handleError(
|
HardcoreData.handleError(
|
||||||
NSError(hardcoreDataErrorCode: .DifferentPersistentStoreExistsAtURL),
|
NSError(hardcoreDataErrorCode: .DifferentPersistentStoreExistsAtURL),
|
||||||
message: "Failed to add SQLite NSPersistentStore at \"\(fileURL)\" because a different NSPersistentStore at that URL already exists.")
|
"Failed to add SQLite NSPersistentStore at \"\(fileURL)\" because a different NSPersistentStore at that URL already exists.")
|
||||||
return PersistentStoreResult(.DifferentPersistentStoreExistsAtURL)
|
return PersistentStoreResult(.DifferentPersistentStoreExistsAtURL)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,7 +175,7 @@ public class DataStack: NSObject {
|
|||||||
|
|
||||||
HardcoreData.handleError(
|
HardcoreData.handleError(
|
||||||
directoryError!,
|
directoryError!,
|
||||||
message: "Failed to create directory for SQLite store at \"\(fileURL)\".")
|
"Failed to create directory for SQLite store at \"\(fileURL)\".")
|
||||||
return PersistentStoreResult(directoryError!)
|
return PersistentStoreResult(directoryError!)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -231,14 +237,14 @@ public class DataStack: NSObject {
|
|||||||
|
|
||||||
HardcoreData.handleError(
|
HardcoreData.handleError(
|
||||||
error,
|
error,
|
||||||
message: "Failed to add SQLite NSPersistentStore at \"\(fileURL)\".")
|
"Failed to add SQLite NSPersistentStore at \"\(fileURL)\".")
|
||||||
return PersistentStoreResult(error)
|
return PersistentStoreResult(error)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
HardcoreData.handleError(
|
HardcoreData.handleError(
|
||||||
NSError(hardcoreDataErrorCode: .UnknownError),
|
NSError(hardcoreDataErrorCode: .UnknownError),
|
||||||
message: "Failed to add SQLite NSPersistentStore at \"\(fileURL)\".")
|
"Failed to add SQLite NSPersistentStore at \"\(fileURL)\".")
|
||||||
}
|
}
|
||||||
return PersistentStoreResult(.UnknownError)
|
return PersistentStoreResult(.UnknownError)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,6 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import CoreData
|
import CoreData
|
||||||
import JEToolkit
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
HardcoreData - Simple, elegant, and smart Core Data management with Swift
|
HardcoreData - Simple, elegant, and smart Core Data management with Swift
|
||||||
@@ -41,30 +40,29 @@ public struct HardcoreData {
|
|||||||
public static var defaultStack = DataStack()
|
public static var defaultStack = DataStack()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The closure that handles all errors that occur within HardcoreData. The default errorHandler logs errors via JEDumpAlert().
|
The closure that handles all errors that occur within HardcoreData. The default errorHandler logs errors via the logHandler closure.
|
||||||
*/
|
*/
|
||||||
public static var errorHandler = { (error: NSError, message: String, fileName: String, lineNumber: UWord, functionName: StaticString) -> () in
|
public static var errorHandler = { (error: NSError, message: String, fileName: StaticString, lineNumber: UWord, functionName: StaticString) -> () in
|
||||||
|
|
||||||
JEDumpAlert(
|
HardcoreData.logHandler("\(message): \(error)", fileName, lineNumber, functionName)
|
||||||
error,
|
|
||||||
message,
|
|
||||||
fileName: fileName,
|
|
||||||
lineNumber: lineNumber,
|
|
||||||
functionName: functionName)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static var assertHandler = { (condition: @autoclosure() -> Bool, message: String, fileName: String, lineNumber: UWord, functionName: StaticString) -> () in
|
/**
|
||||||
|
The closure that handles all assertions that occur within HardcoreData. The default assertHandler calls assert().
|
||||||
|
*/
|
||||||
|
public static var assertHandler = { (condition: @autoclosure() -> Bool, message: String, fileName: StaticString, lineNumber: UWord, functionName: StaticString) -> () in
|
||||||
|
|
||||||
JEAssert(
|
assert(condition, message, file: fileName, line: lineNumber)
|
||||||
condition,
|
|
||||||
message,
|
|
||||||
fileName: fileName,
|
|
||||||
lineNumber: lineNumber,
|
|
||||||
functionName: functionName)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static var logHandler = { (message: String, fileName: String, lineNumber: Int32, functionName: String) -> () in
|
/**
|
||||||
|
The closure that handles all logging that occur within HardcoreData. The default logHandler logs via println() when DEBUG is defined; does nothing otherwise.
|
||||||
|
*/
|
||||||
|
public static var logHandler = { (message: String, fileName: StaticString, lineNumber: UWord, functionName: StaticString) -> () in
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
println("[\(dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL))] \(fileName.stringValue.lastPathComponent):\(lineNumber) \(functionName)\n\(message)")
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -88,14 +86,14 @@ public struct HardcoreData {
|
|||||||
return self.defaultStack.performTransactionAndWait(closure)
|
return self.defaultStack.performTransactionAndWait(closure)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static func handleError(error: NSError, _ message: String, fileName: String = __FILE__, lineNumber: UWord = __LINE__, functionName: StaticString = __FUNCTION__) {
|
internal static func handleError(error: NSError, _ message: String, fileName: StaticString = __FILE__, lineNumber: UWord = __LINE__, functionName: StaticString = __FUNCTION__) {
|
||||||
|
|
||||||
self.errorHandler(error, message, fileName.lastPathComponent, lineNumber, functionName)
|
self.errorHandler(error, message, fileName, lineNumber, functionName)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static func assert(condition: @autoclosure() -> Bool, _ message: String, fileName: String = __FILE__, lineNumber: UWord = __LINE__, functionName: StaticString = __FUNCTION__) {
|
internal static func assert(condition: @autoclosure() -> Bool, _ message: String, fileName: StaticString = __FILE__, lineNumber: UWord = __LINE__, functionName: StaticString = __FUNCTION__) {
|
||||||
|
|
||||||
self.assertHandler(condition, message, fileName.lastPathComponent, lineNumber, functionName)
|
self.assertHandler(condition, message, fileName, lineNumber, functionName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ public extension NSManagedObject {
|
|||||||
|
|
||||||
public class var entityName: String {
|
public class var entityName: String {
|
||||||
|
|
||||||
return self.className().componentsSeparatedByString(".").last!
|
return NSStringFromClass(self).componentsSeparatedByString(".").last!
|
||||||
}
|
}
|
||||||
|
|
||||||
public class func createInContext(context: NSManagedObjectContext) -> Self {
|
public class func createInContext(context: NSManagedObjectContext) -> Self {
|
||||||
@@ -49,7 +49,7 @@ public extension NSManagedObject {
|
|||||||
|
|
||||||
HardcoreData.handleError(
|
HardcoreData.handleError(
|
||||||
permanentIDError!,
|
permanentIDError!,
|
||||||
message: "Failed to obtain permanent ID for object.")
|
"Failed to obtain permanent ID for object.")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -62,7 +62,7 @@ public extension NSManagedObject {
|
|||||||
|
|
||||||
HardcoreData.handleError(
|
HardcoreData.handleError(
|
||||||
existingObjectError!,
|
existingObjectError!,
|
||||||
message: "Failed to load existing NSManagedObject in context.")
|
"Failed to load existing NSManagedObject in context.")
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ public extension NSManagedObjectContext {
|
|||||||
|
|
||||||
HardcoreData.handleError(
|
HardcoreData.handleError(
|
||||||
error!,
|
error!,
|
||||||
message: "Failed executing fetch request.")
|
"Failed executing fetch request.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,7 +98,7 @@ public extension NSManagedObjectContext {
|
|||||||
|
|
||||||
HardcoreData.handleError(
|
HardcoreData.handleError(
|
||||||
error!,
|
error!,
|
||||||
message: "Failed executing fetch request.")
|
"Failed executing fetch request.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,7 +144,7 @@ public extension NSManagedObjectContext {
|
|||||||
|
|
||||||
HardcoreData.handleError(
|
HardcoreData.handleError(
|
||||||
error,
|
error,
|
||||||
message: "Failed to save NSManagedObjectContext.")
|
"Failed to save NSManagedObjectContext.")
|
||||||
result = SaveResult(error)
|
result = SaveResult(error)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -198,7 +198,7 @@ public extension NSManagedObjectContext {
|
|||||||
|
|
||||||
HardcoreData.handleError(
|
HardcoreData.handleError(
|
||||||
error,
|
error,
|
||||||
message: "Failed to save NSManagedObjectContext.")
|
"Failed to save NSManagedObjectContext.")
|
||||||
if let completion = completion {
|
if let completion = completion {
|
||||||
|
|
||||||
GCDBlock.async(.Main) {
|
GCDBlock.async(.Main) {
|
||||||
@@ -233,14 +233,14 @@ public extension NSManagedObjectContext {
|
|||||||
context.parentContext = rootContext
|
context.parentContext = rootContext
|
||||||
context.setupForHardcoreDataWithContextName("com.hardcoredata.maincontext")
|
context.setupForHardcoreDataWithContextName("com.hardcoredata.maincontext")
|
||||||
context.shouldCascadeSavesToParent = true
|
context.shouldCascadeSavesToParent = true
|
||||||
context.registerForNotificationsWithName(
|
context.observerForDidSaveNotification = NotificationObserver(
|
||||||
NSManagedObjectContextDidSaveNotification,
|
notificationName: NSManagedObjectContextDidSaveNotification,
|
||||||
fromObject: rootContext,
|
object: rootContext,
|
||||||
targetQueue: NSOperationQueue.mainQueue()) {
|
closure: { [weak context] (note) -> () in
|
||||||
[unowned context] (note) -> () in
|
|
||||||
|
|
||||||
context.mergeChangesFromContextDidSaveNotification(note)
|
context?.mergeChangesFromContextDidSaveNotification(note)
|
||||||
}
|
return
|
||||||
|
})
|
||||||
|
|
||||||
return context
|
return context
|
||||||
}
|
}
|
||||||
@@ -248,6 +248,40 @@ public extension NSManagedObjectContext {
|
|||||||
|
|
||||||
// MARK: - Private
|
// MARK: - Private
|
||||||
|
|
||||||
|
private struct ObserverKeys {
|
||||||
|
|
||||||
|
static var willSaveNotification: AnyObject?
|
||||||
|
static var didSaveNotification: AnyObject?
|
||||||
|
}
|
||||||
|
|
||||||
|
private var observerForWillSaveNotification: NotificationObserver? {
|
||||||
|
|
||||||
|
get {
|
||||||
|
|
||||||
|
return self.getAssociatedObjectForKey(&ObserverKeys.willSaveNotification)
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
|
||||||
|
self.setAssociatedRetainedObject(
|
||||||
|
newValue,
|
||||||
|
forKey: &ObserverKeys.willSaveNotification)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private var observerForDidSaveNotification: NotificationObserver? {
|
||||||
|
|
||||||
|
get {
|
||||||
|
|
||||||
|
return self.getAssociatedObjectForKey(&ObserverKeys.didSaveNotification)
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
|
||||||
|
self.setAssociatedRetainedObject(
|
||||||
|
newValue,
|
||||||
|
forKey: &ObserverKeys.didSaveNotification)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private var shouldCascadeSavesToParent: Bool {
|
private var shouldCascadeSavesToParent: Bool {
|
||||||
|
|
||||||
get {
|
get {
|
||||||
@@ -275,28 +309,30 @@ public extension NSManagedObjectContext {
|
|||||||
self.name = contextName
|
self.name = contextName
|
||||||
}
|
}
|
||||||
|
|
||||||
self.registerForNotificationsWithName(NSManagedObjectContextWillSaveNotification, fromObject: self) {
|
self.observerForWillSaveNotification = NotificationObserver(
|
||||||
(note) -> () in
|
notificationName: NSManagedObjectContextWillSaveNotification,
|
||||||
|
object: self,
|
||||||
let context: NSManagedObjectContext = note.object as NSManagedObjectContext
|
closure: { (note) -> () in
|
||||||
let insertedObjects = context.insertedObjects
|
|
||||||
if insertedObjects.count <= 0 {
|
|
||||||
|
|
||||||
return
|
let context = note.object as NSManagedObjectContext
|
||||||
}
|
let insertedObjects = context.insertedObjects
|
||||||
|
if insertedObjects.count <= 0 {
|
||||||
var permanentIDError: NSError?
|
|
||||||
if context.obtainPermanentIDsForObjects(insertedObjects.allObjects, error: &permanentIDError) {
|
return
|
||||||
|
}
|
||||||
|
|
||||||
return
|
var permanentIDError: NSError?
|
||||||
}
|
if context.obtainPermanentIDsForObjects(insertedObjects.allObjects, error: &permanentIDError) {
|
||||||
|
|
||||||
if let error = permanentIDError {
|
return
|
||||||
|
}
|
||||||
|
|
||||||
HardcoreData.handleError(
|
if let error = permanentIDError {
|
||||||
error,
|
|
||||||
message: "Failed to obtain permanent IDs for inserted objects.")
|
HardcoreData.handleError(
|
||||||
}
|
error,
|
||||||
}
|
"Failed to obtain permanent IDs for inserted objects.")
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
49
HardcoreData/NSObject+HardcoreData.swift
Normal file
49
HardcoreData/NSObject+HardcoreData.swift
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
//
|
||||||
|
// NSObject+HardcoreData.swift
|
||||||
|
// HardcoreData
|
||||||
|
//
|
||||||
|
// Copyright (c) 2014 John Rommel Estropia
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
|
// copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
// SOFTWARE.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
internal extension NSObject {
|
||||||
|
|
||||||
|
internal func getAssociatedObjectForKey<T: AnyObject>(key: UnsafePointer<Void>) -> T? {
|
||||||
|
|
||||||
|
return objc_getAssociatedObject(self, key) as? T
|
||||||
|
}
|
||||||
|
|
||||||
|
internal func setAssociatedRetainedObject<T: AnyObject>(object: T?, forKey key: UnsafePointer<Void>) {
|
||||||
|
|
||||||
|
objc_setAssociatedObject(self, key, object, UInt(OBJC_ASSOCIATION_RETAIN_NONATOMIC))
|
||||||
|
}
|
||||||
|
|
||||||
|
internal func setAssociatedCopiedObject<T: AnyObject>(object: T?, forKey key: UnsafePointer<Void>) {
|
||||||
|
|
||||||
|
objc_setAssociatedObject(self, key, object, UInt(OBJC_ASSOCIATION_COPY_NONATOMIC))
|
||||||
|
}
|
||||||
|
|
||||||
|
internal func setAssociatedAssignedObject<T: AnyObject>(object: T?, forKey key: UnsafePointer<Void>) {
|
||||||
|
|
||||||
|
objc_setAssociatedObject(self, key, object, UInt(OBJC_ASSOCIATION_ASSIGN))
|
||||||
|
}
|
||||||
|
}
|
||||||
52
HardcoreData/NotificationObserver.swift
Normal file
52
HardcoreData/NotificationObserver.swift
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
//
|
||||||
|
// NotificationObserver.swift
|
||||||
|
// HardcoreData
|
||||||
|
//
|
||||||
|
// Copyright (c) 2014 John Rommel Estropia
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
|
// copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
// SOFTWARE.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
internal class NotificationObserver {
|
||||||
|
|
||||||
|
let notificationName: String
|
||||||
|
let object: AnyObject?
|
||||||
|
let observer: NSObjectProtocol
|
||||||
|
|
||||||
|
init(notificationName: String, object: AnyObject?, closure: (note: NSNotification!) -> ()) {
|
||||||
|
|
||||||
|
self.notificationName = notificationName
|
||||||
|
self.object = object
|
||||||
|
self.observer = NSNotificationCenter.defaultCenter().addObserverForName(
|
||||||
|
notificationName,
|
||||||
|
object: object,
|
||||||
|
queue: nil,
|
||||||
|
usingBlock: closure)
|
||||||
|
}
|
||||||
|
|
||||||
|
deinit {
|
||||||
|
|
||||||
|
NSNotificationCenter.defaultCenter().removeObserver(
|
||||||
|
self.observer,
|
||||||
|
name: self.notificationName,
|
||||||
|
object: self.object)
|
||||||
|
}
|
||||||
|
}
|
||||||
Submodule Libraries/JEToolkit deleted from 5f2a2b3775
Reference in New Issue
Block a user