mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-01-12 20:30:30 +01:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
03973790a8 |
@@ -1,6 +1,6 @@
|
||||
Pod::Spec.new do |s|
|
||||
s.name = "CoreStore"
|
||||
s.version = "3.0.2"
|
||||
s.version = "3.0.3"
|
||||
s.license = "MIT"
|
||||
s.summary = "Unleashing the real power of Core Data with the elegance and safety of Swift"
|
||||
s.homepage = "https://github.com/JohnEstropia/CoreStore"
|
||||
|
||||
@@ -378,8 +378,10 @@
|
||||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||
CLANG_WARN_EMPTY_BODY = YES;
|
||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||
CLANG_WARN_INFINITE_RECURSION = YES;
|
||||
CLANG_WARN_INT_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
|
||||
@@ -423,8 +425,10 @@
|
||||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||
CLANG_WARN_EMPTY_BODY = YES;
|
||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||
CLANG_WARN_INFINITE_RECURSION = YES;
|
||||
CLANG_WARN_INT_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>FMWK</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>3.0.2</string>
|
||||
<string>3.0.3</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
|
||||
@@ -31,210 +31,211 @@ import CoreData
|
||||
|
||||
internal extension NSManagedObject {
|
||||
|
||||
@nonobjc
|
||||
internal static func cs_swizzleMethodsForLogging() {
|
||||
|
||||
struct Static {
|
||||
|
||||
static let isSwizzled = Static.swizzle()
|
||||
|
||||
private static func swizzle() -> Bool {
|
||||
|
||||
NSManagedObject.cs_swizzle(
|
||||
original: #selector(NSManagedObject.willAccessValue(forKey:)),
|
||||
proxy: #selector(NSManagedObject.cs_willAccessValue(forKey:))
|
||||
)
|
||||
NSManagedObject.cs_swizzle(
|
||||
original: #selector(NSManagedObject.willChangeValue(forKey:)),
|
||||
proxy: #selector(NSManagedObject.cs_willChangeValue(forKey:))
|
||||
)
|
||||
NSManagedObject.cs_swizzle(
|
||||
original: #selector(NSManagedObject.willChangeValue(forKey:withSetMutation:using:)),
|
||||
proxy: #selector(NSManagedObject.cs_willChangeValue(forKey:withSetMutation:using:))
|
||||
)
|
||||
return true
|
||||
}
|
||||
}
|
||||
assert(Static.isSwizzled)
|
||||
}
|
||||
|
||||
@nonobjc
|
||||
private static func cs_swizzle(original originalSelector: Selector, proxy swizzledSelector: Selector) {
|
||||
|
||||
let originalMethod = class_getInstanceMethod(NSManagedObject.self, originalSelector)
|
||||
let swizzledMethod = class_getInstanceMethod(NSManagedObject.self, swizzledSelector)
|
||||
let didAddMethod = class_addMethod(
|
||||
NSManagedObject.self,
|
||||
originalSelector,
|
||||
method_getImplementation(swizzledMethod),
|
||||
method_getTypeEncoding(swizzledMethod)
|
||||
)
|
||||
if didAddMethod {
|
||||
|
||||
class_replaceMethod(
|
||||
NSManagedObject.self,
|
||||
swizzledSelector,
|
||||
method_getImplementation(originalMethod),
|
||||
method_getTypeEncoding(originalMethod)
|
||||
)
|
||||
}
|
||||
else {
|
||||
|
||||
method_exchangeImplementations(originalMethod, swizzledMethod)
|
||||
}
|
||||
}
|
||||
|
||||
private dynamic func cs_willAccessValue(forKey key: String?) {
|
||||
|
||||
self.cs_willAccessValue(forKey: key)
|
||||
|
||||
guard CoreStore.logger.enableObjectConcurrencyDebugging else {
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
guard let context = self.managedObjectContext else {
|
||||
|
||||
CoreStore.log(
|
||||
.warning,
|
||||
message: "Attempted to access the \"\(key ?? "")\" key of an object of type \(cs_typeName(self)) after has been deleted from its \(cs_typeName(NSManagedObjectContext.self))."
|
||||
)
|
||||
return
|
||||
}
|
||||
if context.isTransactionContext {
|
||||
|
||||
guard let transaction = context.parentTransaction else {
|
||||
|
||||
CoreStore.log(
|
||||
.warning,
|
||||
message: "Attempted to access the \"\(key ?? "")\" key of an object of type \(cs_typeName(self)) after has been deleted from its transaction."
|
||||
)
|
||||
return
|
||||
}
|
||||
CoreStore.assert(
|
||||
transaction.isRunningInAllowedQueue(),
|
||||
"Attempted to access the \"\(key ?? "")\" key of an object of type \(cs_typeName(self)) outside its transaction's designated queue."
|
||||
)
|
||||
return
|
||||
}
|
||||
if context.isDataStackContext {
|
||||
|
||||
guard context.parentStack != nil else {
|
||||
|
||||
CoreStore.log(
|
||||
.warning,
|
||||
message: "Attempted to access the \"\(key ?? "")\" key of an object of type \(cs_typeName(self)) after has been deleted from its \(cs_typeName(DataStack.self)).")
|
||||
return
|
||||
}
|
||||
CoreStore.assert(
|
||||
Thread.isMainThread,
|
||||
"Attempted to access the \"\(key ?? "")\" key of an object of type \(cs_typeName(self)) outside the main thread."
|
||||
)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
private dynamic func cs_willChangeValue(forKey key: String?) {
|
||||
|
||||
self.cs_willChangeValue(forKey: key)
|
||||
|
||||
guard CoreStore.logger.enableObjectConcurrencyDebugging else {
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
guard let context = self.managedObjectContext else {
|
||||
|
||||
CoreStore.log(
|
||||
.warning,
|
||||
message: "Attempted to change the \"\(key ?? "")\" of an object of type \(cs_typeName(self)) after has been deleted from its \(cs_typeName(NSManagedObjectContext.self))."
|
||||
)
|
||||
return
|
||||
}
|
||||
if context.isTransactionContext {
|
||||
|
||||
guard let transaction = context.parentTransaction else {
|
||||
|
||||
CoreStore.log(
|
||||
.warning,
|
||||
message: "Attempted to change the \"\(key ?? "")\" of an object of type \(cs_typeName(self)) after has been deleted from its transaction."
|
||||
)
|
||||
return
|
||||
}
|
||||
CoreStore.assert(
|
||||
transaction.isRunningInAllowedQueue(),
|
||||
"Attempted to change the \"\(key ?? "")\" of an object of type \(cs_typeName(self)) outside its transaction's designated queue."
|
||||
)
|
||||
return
|
||||
}
|
||||
if context.isDataStackContext {
|
||||
|
||||
guard context.parentStack != nil else {
|
||||
|
||||
CoreStore.log(
|
||||
.warning,
|
||||
message: "Attempted to change the \"\(key ?? "")\" of an object of type \(cs_typeName(self)) after has been deleted from its \(cs_typeName(DataStack.self)).")
|
||||
return
|
||||
}
|
||||
CoreStore.assert(
|
||||
Thread.isMainThread,
|
||||
"Attempted to change the \"\(key ?? "")\" of an object of type \(cs_typeName(self)) outside the main thread."
|
||||
)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
private dynamic func cs_willChangeValue(forKey inKey: String, withSetMutation inMutationKind: NSKeyValueSetMutationKind, using inObjects: Set<AnyHashable>) {
|
||||
|
||||
self.cs_willChangeValue(
|
||||
forKey: inKey,
|
||||
withSetMutation: inMutationKind,
|
||||
using: inObjects
|
||||
)
|
||||
|
||||
guard CoreStore.logger.enableObjectConcurrencyDebugging else {
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
guard let context = self.managedObjectContext else {
|
||||
|
||||
CoreStore.log(
|
||||
.warning,
|
||||
message: "Attempted to mutate the \"\(inKey)\" of an object of type \(cs_typeName(self)) after has been deleted from its \(cs_typeName(NSManagedObjectContext.self))."
|
||||
)
|
||||
return
|
||||
}
|
||||
if context.isTransactionContext {
|
||||
|
||||
guard let transaction = context.parentTransaction else {
|
||||
|
||||
CoreStore.log(
|
||||
.warning,
|
||||
message: "Attempted to mutate the \"\(inKey)\" of an object of type \(cs_typeName(self)) after has been deleted from its transaction."
|
||||
)
|
||||
return
|
||||
}
|
||||
CoreStore.assert(
|
||||
transaction.isRunningInAllowedQueue(),
|
||||
"Attempted to mutate the \"\(inKey)\" of an object of type \(cs_typeName(self)) outside its transaction's designated queue."
|
||||
)
|
||||
return
|
||||
}
|
||||
if context.isDataStackContext {
|
||||
|
||||
guard context.parentStack != nil else {
|
||||
|
||||
CoreStore.log(
|
||||
.warning,
|
||||
message: "Attempted to mutate the \"\(inKey)\" of an object of type \(cs_typeName(self)) after has been deleted from its \(cs_typeName(DataStack.self)).")
|
||||
return
|
||||
}
|
||||
CoreStore.assert(
|
||||
Thread.isMainThread,
|
||||
"Attempted to mutate the \"\(inKey)\" of an object of type \(cs_typeName(self)) outside the main thread."
|
||||
)
|
||||
return
|
||||
}
|
||||
}
|
||||
// TODO: test before release (rolled back)
|
||||
// @nonobjc
|
||||
// internal static func cs_swizzleMethodsForLogging() {
|
||||
//
|
||||
// struct Static {
|
||||
//
|
||||
// static let isSwizzled = Static.swizzle()
|
||||
//
|
||||
// private static func swizzle() -> Bool {
|
||||
//
|
||||
// NSManagedObject.cs_swizzle(
|
||||
// original: #selector(NSManagedObject.willAccessValue(forKey:)),
|
||||
// proxy: #selector(NSManagedObject.cs_willAccessValue(forKey:))
|
||||
// )
|
||||
// NSManagedObject.cs_swizzle(
|
||||
// original: #selector(NSManagedObject.willChangeValue(forKey:)),
|
||||
// proxy: #selector(NSManagedObject.cs_willChangeValue(forKey:))
|
||||
// )
|
||||
// NSManagedObject.cs_swizzle(
|
||||
// original: #selector(NSManagedObject.willChangeValue(forKey:withSetMutation:using:)),
|
||||
// proxy: #selector(NSManagedObject.cs_willChangeValue(forKey:withSetMutation:using:))
|
||||
// )
|
||||
// return true
|
||||
// }
|
||||
// }
|
||||
// assert(Static.isSwizzled)
|
||||
// }
|
||||
//
|
||||
// @nonobjc
|
||||
// private static func cs_swizzle(original originalSelector: Selector, proxy swizzledSelector: Selector) {
|
||||
//
|
||||
// let originalMethod = class_getInstanceMethod(NSManagedObject.self, originalSelector)
|
||||
// let swizzledMethod = class_getInstanceMethod(NSManagedObject.self, swizzledSelector)
|
||||
// let didAddMethod = class_addMethod(
|
||||
// NSManagedObject.self,
|
||||
// originalSelector,
|
||||
// method_getImplementation(swizzledMethod),
|
||||
// method_getTypeEncoding(swizzledMethod)
|
||||
// )
|
||||
// if didAddMethod {
|
||||
//
|
||||
// class_replaceMethod(
|
||||
// NSManagedObject.self,
|
||||
// swizzledSelector,
|
||||
// method_getImplementation(originalMethod),
|
||||
// method_getTypeEncoding(originalMethod)
|
||||
// )
|
||||
// }
|
||||
// else {
|
||||
//
|
||||
// method_exchangeImplementations(originalMethod, swizzledMethod)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private dynamic func cs_willAccessValue(forKey key: String?) {
|
||||
//
|
||||
// self.cs_willAccessValue(forKey: key)
|
||||
//
|
||||
// guard CoreStore.logger.enableObjectConcurrencyDebugging else {
|
||||
//
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// guard let context = self.managedObjectContext else {
|
||||
//
|
||||
// CoreStore.log(
|
||||
// .warning,
|
||||
// message: "Attempted to access the \"\(key ?? "")\" key of an object of type \(cs_typeName(self)) after has been deleted from its \(cs_typeName(NSManagedObjectContext.self))."
|
||||
// )
|
||||
// return
|
||||
// }
|
||||
// if context.isTransactionContext {
|
||||
//
|
||||
// guard let transaction = context.parentTransaction else {
|
||||
//
|
||||
// CoreStore.log(
|
||||
// .warning,
|
||||
// message: "Attempted to access the \"\(key ?? "")\" key of an object of type \(cs_typeName(self)) after has been deleted from its transaction."
|
||||
// )
|
||||
// return
|
||||
// }
|
||||
// CoreStore.assert(
|
||||
// transaction.isRunningInAllowedQueue(),
|
||||
// "Attempted to access the \"\(key ?? "")\" key of an object of type \(cs_typeName(self)) outside its transaction's designated queue."
|
||||
// )
|
||||
// return
|
||||
// }
|
||||
// if context.isDataStackContext {
|
||||
//
|
||||
// guard context.parentStack != nil else {
|
||||
//
|
||||
// CoreStore.log(
|
||||
// .warning,
|
||||
// message: "Attempted to access the \"\(key ?? "")\" key of an object of type \(cs_typeName(self)) after has been deleted from its \(cs_typeName(DataStack.self)).")
|
||||
// return
|
||||
// }
|
||||
// CoreStore.assert(
|
||||
// Thread.isMainThread,
|
||||
// "Attempted to access the \"\(key ?? "")\" key of an object of type \(cs_typeName(self)) outside the main thread."
|
||||
// )
|
||||
// return
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private dynamic func cs_willChangeValue(forKey key: String?) {
|
||||
//
|
||||
// self.cs_willChangeValue(forKey: key)
|
||||
//
|
||||
// guard CoreStore.logger.enableObjectConcurrencyDebugging else {
|
||||
//
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// guard let context = self.managedObjectContext else {
|
||||
//
|
||||
// CoreStore.log(
|
||||
// .warning,
|
||||
// message: "Attempted to change the \"\(key ?? "")\" of an object of type \(cs_typeName(self)) after has been deleted from its \(cs_typeName(NSManagedObjectContext.self))."
|
||||
// )
|
||||
// return
|
||||
// }
|
||||
// if context.isTransactionContext {
|
||||
//
|
||||
// guard let transaction = context.parentTransaction else {
|
||||
//
|
||||
// CoreStore.log(
|
||||
// .warning,
|
||||
// message: "Attempted to change the \"\(key ?? "")\" of an object of type \(cs_typeName(self)) after has been deleted from its transaction."
|
||||
// )
|
||||
// return
|
||||
// }
|
||||
// CoreStore.assert(
|
||||
// transaction.isRunningInAllowedQueue(),
|
||||
// "Attempted to change the \"\(key ?? "")\" of an object of type \(cs_typeName(self)) outside its transaction's designated queue."
|
||||
// )
|
||||
// return
|
||||
// }
|
||||
// if context.isDataStackContext {
|
||||
//
|
||||
// guard context.parentStack != nil else {
|
||||
//
|
||||
// CoreStore.log(
|
||||
// .warning,
|
||||
// message: "Attempted to change the \"\(key ?? "")\" of an object of type \(cs_typeName(self)) after has been deleted from its \(cs_typeName(DataStack.self)).")
|
||||
// return
|
||||
// }
|
||||
// CoreStore.assert(
|
||||
// Thread.isMainThread,
|
||||
// "Attempted to change the \"\(key ?? "")\" of an object of type \(cs_typeName(self)) outside the main thread."
|
||||
// )
|
||||
// return
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private dynamic func cs_willChangeValue(forKey inKey: String, withSetMutation inMutationKind: NSKeyValueSetMutationKind, using inObjects: Set<AnyHashable>) {
|
||||
//
|
||||
// self.cs_willChangeValue(
|
||||
// forKey: inKey,
|
||||
// withSetMutation: inMutationKind,
|
||||
// using: inObjects
|
||||
// )
|
||||
//
|
||||
// guard CoreStore.logger.enableObjectConcurrencyDebugging else {
|
||||
//
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// guard let context = self.managedObjectContext else {
|
||||
//
|
||||
// CoreStore.log(
|
||||
// .warning,
|
||||
// message: "Attempted to mutate the \"\(inKey)\" of an object of type \(cs_typeName(self)) after has been deleted from its \(cs_typeName(NSManagedObjectContext.self))."
|
||||
// )
|
||||
// return
|
||||
// }
|
||||
// if context.isTransactionContext {
|
||||
//
|
||||
// guard let transaction = context.parentTransaction else {
|
||||
//
|
||||
// CoreStore.log(
|
||||
// .warning,
|
||||
// message: "Attempted to mutate the \"\(inKey)\" of an object of type \(cs_typeName(self)) after has been deleted from its transaction."
|
||||
// )
|
||||
// return
|
||||
// }
|
||||
// CoreStore.assert(
|
||||
// transaction.isRunningInAllowedQueue(),
|
||||
// "Attempted to mutate the \"\(inKey)\" of an object of type \(cs_typeName(self)) outside its transaction's designated queue."
|
||||
// )
|
||||
// return
|
||||
// }
|
||||
// if context.isDataStackContext {
|
||||
//
|
||||
// guard context.parentStack != nil else {
|
||||
//
|
||||
// CoreStore.log(
|
||||
// .warning,
|
||||
// message: "Attempted to mutate the \"\(inKey)\" of an object of type \(cs_typeName(self)) after has been deleted from its \(cs_typeName(DataStack.self)).")
|
||||
// return
|
||||
// }
|
||||
// CoreStore.assert(
|
||||
// Thread.isMainThread,
|
||||
// "Attempted to mutate the \"\(inKey)\" of an object of type \(cs_typeName(self)) outside the main thread."
|
||||
// )
|
||||
// return
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -50,7 +50,8 @@ public protocol CoreStoreLogger {
|
||||
/**
|
||||
When `true`, all `NSManagedObject` attribute and relationship access will raise an assertion when executed on the wrong transaction/datastack queue. Defaults to `false` if not implemented.
|
||||
*/
|
||||
var enableObjectConcurrencyDebugging: Bool { get set }
|
||||
// TODO: test before release (rolled back)
|
||||
// var enableObjectConcurrencyDebugging: Bool { get set }
|
||||
|
||||
/**
|
||||
Handles log messages sent by the `CoreStore` framework.
|
||||
@@ -99,11 +100,12 @@ public protocol CoreStoreLogger {
|
||||
|
||||
extension CoreStoreLogger {
|
||||
|
||||
public var enableObjectConcurrencyDebugging: Bool {
|
||||
|
||||
get { return false }
|
||||
set {}
|
||||
}
|
||||
// TODO: test before release (rolled back)
|
||||
// public var enableObjectConcurrencyDebugging: Bool {
|
||||
//
|
||||
// get { return false }
|
||||
// set {}
|
||||
// }
|
||||
|
||||
public func abort(_ message: String, fileName: StaticString, lineNumber: Int, functionName: StaticString) {
|
||||
|
||||
|
||||
@@ -36,7 +36,8 @@ public final class DefaultLogger: CoreStoreLogger {
|
||||
/**
|
||||
When `true`, all `NSManagedObject` attribute and relationship access will raise an assertion when executed on the wrong transaction/datastack queue. Defaults to `false`.
|
||||
*/
|
||||
public var enableObjectConcurrencyDebugging: Bool = false
|
||||
// TODO: test before release (rolled back)
|
||||
// public var enableObjectConcurrencyDebugging: Bool = false
|
||||
|
||||
/**
|
||||
Creates a `DefaultLogger`.
|
||||
|
||||
@@ -58,8 +58,9 @@ public final class DataStack: Equatable {
|
||||
- parameter migrationChain: the `MigrationChain` that indicates the sequence of model versions to be used as the order for progressive migrations. If not specified, will default to a non-migrating data stack.
|
||||
*/
|
||||
public required init(model: NSManagedObjectModel, migrationChain: MigrationChain = nil) {
|
||||
|
||||
_ = DataStack.isGloballyInitialized
|
||||
|
||||
// TODO: test before release (rolled back)
|
||||
// _ = DataStack.isGloballyInitialized
|
||||
|
||||
CoreStore.assert(
|
||||
migrationChain.valid,
|
||||
@@ -501,11 +502,12 @@ public final class DataStack: Equatable {
|
||||
|
||||
// MARK: Private
|
||||
|
||||
private static let isGloballyInitialized: Bool = {
|
||||
|
||||
NSManagedObject.cs_swizzleMethodsForLogging()
|
||||
return true
|
||||
}()
|
||||
// TODO: test before release (rolled back)
|
||||
// private static let isGloballyInitialized: Bool = {
|
||||
//
|
||||
// NSManagedObject.cs_swizzleMethodsForLogging()
|
||||
// return true
|
||||
// }()
|
||||
|
||||
private var configurationStoreMapping = [String: NSPersistentStore]()
|
||||
private var entityConfigurationsMapping = [String: Set<String>]()
|
||||
|
||||
Reference in New Issue
Block a user