mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-01-12 12:20:30 +01:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
19fea6953a | ||
|
|
698326f89a | ||
|
|
bdf6308d8f | ||
|
|
69d96c53d6 | ||
|
|
7b961fa249 |
@@ -1,6 +1,6 @@
|
||||
Pod::Spec.new do |s|
|
||||
s.name = "CoreStore"
|
||||
s.version = "3.0.1"
|
||||
s.version = "3.0.2"
|
||||
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"
|
||||
|
||||
@@ -197,6 +197,10 @@
|
||||
B52DD1C91BE1F94600949AFE /* NSManagedObjectContext+Transaction.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E84F331AFF85470064E85B /* NSManagedObjectContext+Transaction.swift */; };
|
||||
B52DD1CA1BE1F94600949AFE /* NSManagedObjectModel+Setup.swift in Sources */ = {isa = PBXBuildFile; fileRef = B51BE0691B47FC4B0069F532 /* NSManagedObjectModel+Setup.swift */; };
|
||||
B52DD1CB1BE1F94600949AFE /* WeakObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E84F2D1AFF849C0064E85B /* WeakObject.swift */; };
|
||||
B52FD3AA1E3B3EF10001D919 /* NSManagedObject+Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = B52FD3A91E3B3EF10001D919 /* NSManagedObject+Logging.swift */; };
|
||||
B52FD3AB1E3B3EF10001D919 /* NSManagedObject+Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = B52FD3A91E3B3EF10001D919 /* NSManagedObject+Logging.swift */; };
|
||||
B52FD3AC1E3B3EF10001D919 /* NSManagedObject+Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = B52FD3A91E3B3EF10001D919 /* NSManagedObject+Logging.swift */; };
|
||||
B52FD3AD1E3B3EF10001D919 /* NSManagedObject+Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = B52FD3A91E3B3EF10001D919 /* NSManagedObject+Logging.swift */; };
|
||||
B533C4DB1D7D4BFA001383CB /* DispatchQueue+CoreStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = B533C4DA1D7D4BFA001383CB /* DispatchQueue+CoreStore.swift */; };
|
||||
B533C4DC1D7D4BFA001383CB /* DispatchQueue+CoreStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = B533C4DA1D7D4BFA001383CB /* DispatchQueue+CoreStore.swift */; };
|
||||
B533C4DD1D7D4BFA001383CB /* DispatchQueue+CoreStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = B533C4DA1D7D4BFA001383CB /* DispatchQueue+CoreStore.swift */; };
|
||||
@@ -619,6 +623,7 @@
|
||||
B529C2031CA4A2DB007E7EBD /* CSSaveResult.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CSSaveResult.swift; sourceTree = "<group>"; };
|
||||
B52DD1741BE1F8CC00949AFE /* CoreStore.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = CoreStore.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
B52DD17D1BE1F8CC00949AFE /* CoreStoreTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = CoreStoreTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
B52FD3A91E3B3EF10001D919 /* NSManagedObject+Logging.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSManagedObject+Logging.swift"; sourceTree = "<group>"; };
|
||||
B533C4DA1D7D4BFA001383CB /* DispatchQueue+CoreStore.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "DispatchQueue+CoreStore.swift"; sourceTree = "<group>"; };
|
||||
B538BA701D15B3E30003A766 /* CoreStoreBridge.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CoreStoreBridge.m; sourceTree = "<group>"; };
|
||||
B53FB9FD1CAB2D2F00F0D40A /* CSMigrationResult.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CSMigrationResult.swift; sourceTree = "<group>"; };
|
||||
@@ -1210,6 +1215,7 @@
|
||||
B5FAD6AB1B51285300714891 /* MigrationManager.swift */,
|
||||
B5E84F2B1AFF849C0064E85B /* NotificationObserver.swift */,
|
||||
B533C4DA1D7D4BFA001383CB /* DispatchQueue+CoreStore.swift */,
|
||||
B52FD3A91E3B3EF10001D919 /* NSManagedObject+Logging.swift */,
|
||||
B5E84F2C1AFF849C0064E85B /* NSManagedObjectContext+CoreStore.swift */,
|
||||
B5E84F351AFF85470064E85B /* NSManagedObjectContext+Querying.swift */,
|
||||
B5E84F321AFF85470064E85B /* NSManagedObjectContext+Setup.swift */,
|
||||
@@ -1558,6 +1564,7 @@
|
||||
B5ECDC051CA8138100C7F112 /* CSOrderBy.swift in Sources */,
|
||||
B5E1B5981CAA0C23007FD580 /* CSObjectObserver.swift in Sources */,
|
||||
B5519A5F1CA21954002BEF78 /* CSAsynchronousDataTransaction.swift in Sources */,
|
||||
B52FD3AA1E3B3EF10001D919 /* NSManagedObject+Logging.swift in Sources */,
|
||||
B51FE5AB1CD4D00300E54258 /* CoreStore+CustomDebugStringConvertible.swift in Sources */,
|
||||
B54A6A551BA15F2A007870FD /* FetchedResultsControllerDelegate.swift in Sources */,
|
||||
B5A261211B64BFDB006EB6D3 /* MigrationType.swift in Sources */,
|
||||
@@ -1711,6 +1718,7 @@
|
||||
B5ECDC071CA8138100C7F112 /* CSOrderBy.swift in Sources */,
|
||||
B5E1B59A1CAA0C23007FD580 /* CSObjectObserver.swift in Sources */,
|
||||
B5519A601CA21954002BEF78 /* CSAsynchronousDataTransaction.swift in Sources */,
|
||||
B52FD3AB1E3B3EF10001D919 /* NSManagedObject+Logging.swift in Sources */,
|
||||
B51FE5AD1CD4D00300E54258 /* CoreStore+CustomDebugStringConvertible.swift in Sources */,
|
||||
B5FE4DAD1C85D44E00FA6A91 /* SQLiteStore.swift in Sources */,
|
||||
82BA18C51C4BBD5300A0916E /* ListObserver.swift in Sources */,
|
||||
@@ -1864,6 +1872,7 @@
|
||||
B5ECDC0F1CA8161B00C7F112 /* CSGroupBy.swift in Sources */,
|
||||
B5ECDC211CA81A2100C7F112 /* CSDataStack+Querying.swift in Sources */,
|
||||
B52DD1C21BE1F94600949AFE /* MigrationManager.swift in Sources */,
|
||||
B52FD3AD1E3B3EF10001D919 /* NSManagedObject+Logging.swift in Sources */,
|
||||
B5ECDC2D1CA81CC700C7F112 /* CSDataStack+Transaction.swift in Sources */,
|
||||
B5D7A5BA1CA3BF8F005C752B /* CSInto.swift in Sources */,
|
||||
B5A5F26A1CAEC50F004AB9AF /* CSSelect.swift in Sources */,
|
||||
@@ -2017,6 +2026,7 @@
|
||||
B5E1B59B1CAA0C23007FD580 /* CSObjectObserver.swift in Sources */,
|
||||
B5519A611CA21954002BEF78 /* CSAsynchronousDataTransaction.swift in Sources */,
|
||||
B5FE4DAE1C85D44E00FA6A91 /* SQLiteStore.swift in Sources */,
|
||||
B52FD3AC1E3B3EF10001D919 /* NSManagedObject+Logging.swift in Sources */,
|
||||
B51FE5AE1CD4D00300E54258 /* CoreStore+CustomDebugStringConvertible.swift in Sources */,
|
||||
B563218C1BD65216006C9394 /* DataStack+Transaction.swift in Sources */,
|
||||
B53FBA0E1CAB5E6500F0D40A /* CSCoreStore+Migrating.swift in Sources */,
|
||||
|
||||
@@ -153,6 +153,8 @@ class TestLogger: CoreStoreLogger {
|
||||
|
||||
// MARK: CoreStoreLogger
|
||||
|
||||
var enableObjectConcurrencyDebugging: Bool = true
|
||||
|
||||
func log(level: LogLevel, message: String, fileName: StaticString, lineNumber: Int, functionName: StaticString) {
|
||||
|
||||
switch level {
|
||||
|
||||
@@ -206,7 +206,7 @@ public struct From<T: NSManagedObject> {
|
||||
return stores?.isEmpty == false
|
||||
}
|
||||
|
||||
internal func upcast() -> From<NSManagedObject> {
|
||||
internal func downcast() -> From<NSManagedObject> {
|
||||
|
||||
return From<NSManagedObject>(
|
||||
entityClass: self.entityClass,
|
||||
|
||||
@@ -169,7 +169,7 @@ extension Bool: CoreStoreSupportedAttributeType {
|
||||
|
||||
public static func cs_fromNativeType(_ value: CoreStoreNativeType) -> Bool? {
|
||||
|
||||
return value as Bool
|
||||
return value.boolValue
|
||||
}
|
||||
|
||||
public func cs_toNativeType() -> CoreStoreNativeType {
|
||||
@@ -184,7 +184,7 @@ extension Int16: CoreStoreSupportedAttributeType {
|
||||
|
||||
public static func cs_fromNativeType(_ value: CoreStoreNativeType) -> Int16? {
|
||||
|
||||
return value as Int16
|
||||
return value.int16Value
|
||||
}
|
||||
|
||||
public func cs_toNativeType() -> CoreStoreNativeType {
|
||||
@@ -199,7 +199,7 @@ extension Int32: CoreStoreSupportedAttributeType {
|
||||
|
||||
public static func cs_fromNativeType(_ value: CoreStoreNativeType) -> Int32? {
|
||||
|
||||
return value as Int32
|
||||
return value.int32Value
|
||||
}
|
||||
|
||||
public func cs_toNativeType() -> CoreStoreNativeType {
|
||||
@@ -214,7 +214,7 @@ extension Int64: CoreStoreSupportedAttributeType {
|
||||
|
||||
public static func cs_fromNativeType(_ value: CoreStoreNativeType) -> Int64? {
|
||||
|
||||
return value as Int64
|
||||
return value.int64Value
|
||||
}
|
||||
|
||||
public func cs_toNativeType() -> CoreStoreNativeType {
|
||||
@@ -229,7 +229,7 @@ extension Double: CoreStoreSupportedAttributeType {
|
||||
|
||||
public static func cs_fromNativeType(_ value: CoreStoreNativeType) -> Double? {
|
||||
|
||||
return value as Double
|
||||
return value.doubleValue
|
||||
}
|
||||
|
||||
public func cs_toNativeType() -> CoreStoreNativeType {
|
||||
@@ -244,7 +244,7 @@ extension Float: CoreStoreSupportedAttributeType {
|
||||
|
||||
public static func cs_fromNativeType(_ value: CoreStoreNativeType) -> Float? {
|
||||
|
||||
return value as Float
|
||||
return value.floatValue
|
||||
}
|
||||
|
||||
public func cs_toNativeType() -> CoreStoreNativeType {
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>FMWK</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>3.0.1</string>
|
||||
<string>3.0.2</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
|
||||
240
Sources/Internal/NSManagedObject+Logging.swift
Normal file
240
Sources/Internal/NSManagedObject+Logging.swift
Normal file
@@ -0,0 +1,240 @@
|
||||
//
|
||||
// NSManagedObject+Logging.swift
|
||||
// CoreStore
|
||||
//
|
||||
// Copyright © 2017 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
|
||||
import CoreData
|
||||
|
||||
|
||||
// MARK: - NSManagedObject
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,10 @@ internal extension NSManagedObjectModel {
|
||||
guard let modelFilePath = bundle.path(forResource: modelName, ofType: "momd") else {
|
||||
|
||||
// For users migrating from very old Xcode versions: Old xcdatamodel files are not contained inside xcdatamodeld (with a "d"), and will thus fail this check. If that was the case, create a new xcdatamodeld file and copy all contents into the new model.
|
||||
CoreStore.abort("Could not find \"\(modelName).momd\" from the bundle. \(bundle)")
|
||||
let foundModels = bundle
|
||||
.paths(forResourcesOfType: "momd", inDirectory: nil)
|
||||
.map({ ($0 as NSString).lastPathComponent })
|
||||
CoreStore.abort("Could not find \"\(modelName).momd\" from the bundle \"\(bundle.bundleIdentifier ?? "<nil>")\". Other model files in bundle: \(foundModels.coreStoreDumpString)")
|
||||
}
|
||||
|
||||
let modelFileURL = URL(fileURLWithPath: modelFilePath)
|
||||
@@ -120,7 +123,7 @@ internal extension NSManagedObjectModel {
|
||||
&PropertyKeys.currentModelVersion,
|
||||
inObject: self
|
||||
)
|
||||
return value as? String
|
||||
return value as String?
|
||||
}
|
||||
set {
|
||||
|
||||
|
||||
@@ -47,6 +47,11 @@ public enum LogLevel {
|
||||
*/
|
||||
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 }
|
||||
|
||||
/**
|
||||
Handles log messages sent by the `CoreStore` framework.
|
||||
|
||||
@@ -94,6 +99,12 @@ public protocol CoreStoreLogger {
|
||||
|
||||
extension CoreStoreLogger {
|
||||
|
||||
public var enableObjectConcurrencyDebugging: Bool {
|
||||
|
||||
get { return false }
|
||||
set {}
|
||||
}
|
||||
|
||||
public func abort(_ message: String, fileName: StaticString, lineNumber: Int, functionName: StaticString) {
|
||||
|
||||
Swift.fatalError(message, file: fileName, line: UInt(lineNumber))
|
||||
|
||||
@@ -33,6 +33,11 @@ import Foundation
|
||||
*/
|
||||
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
|
||||
|
||||
/**
|
||||
Creates a `DefaultLogger`.
|
||||
*/
|
||||
|
||||
@@ -168,5 +168,8 @@ extension AsynchronousDataTransaction: CoreStoreSwiftType {
|
||||
|
||||
// MARK: CoreStoreSwiftType
|
||||
|
||||
public typealias ObjectiveCType = CSAsynchronousDataTransaction
|
||||
public var bridgeToObjectiveC: CSAsynchronousDataTransaction {
|
||||
|
||||
return CSAsynchronousDataTransaction(self)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -294,13 +294,3 @@ public class CSBaseDataTransaction: NSObject, CoreStoreObjectiveCType {
|
||||
|
||||
private let swiftTransaction: BaseDataTransaction
|
||||
}
|
||||
|
||||
|
||||
//// MARK: - BaseDataTransaction
|
||||
//
|
||||
//extension BaseDataTransaction: CoreStoreSwiftType {
|
||||
//
|
||||
// // MARK: CoreStoreSwiftType
|
||||
//
|
||||
// public typealias ObjectiveCType = CSBaseDataTransaction
|
||||
//}
|
||||
|
||||
@@ -277,5 +277,8 @@ extension DataStack: CoreStoreSwiftType {
|
||||
|
||||
// MARK: CoreStoreSwiftType
|
||||
|
||||
public typealias ObjectiveCType = CSDataStack
|
||||
public var bridgeToObjectiveC: CSDataStack {
|
||||
|
||||
return CSDataStack(self)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,7 +146,7 @@ public final class CSFrom: NSObject, CoreStoreObjectiveCType {
|
||||
|
||||
public init<T: NSManagedObject>(_ swiftValue: From<T>) {
|
||||
|
||||
self.bridgeToSwift = swiftValue.upcast()
|
||||
self.bridgeToSwift = swiftValue.downcast()
|
||||
super.init()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,5 +118,8 @@ extension GroupBy: CoreStoreSwiftType {
|
||||
|
||||
// MARK: CoreStoreSwiftType
|
||||
|
||||
public typealias ObjectiveCType = CSGroupBy
|
||||
public var bridgeToObjectiveC: CSGroupBy {
|
||||
|
||||
return CSGroupBy(self)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,5 +125,8 @@ extension InMemoryStore: CoreStoreSwiftType {
|
||||
|
||||
// MARK: CoreStoreSwiftType
|
||||
|
||||
public typealias ObjectiveCType = CSInMemoryStore
|
||||
public var bridgeToObjectiveC: CSInMemoryStore {
|
||||
|
||||
return CSInMemoryStore(self)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ public final class CSInto: NSObject, CoreStoreObjectiveCType {
|
||||
|
||||
public required init<T: NSManagedObject>(_ swiftValue: Into<T>) {
|
||||
|
||||
self.bridgeToSwift = swiftValue.upcast()
|
||||
self.bridgeToSwift = swiftValue.downcast()
|
||||
super.init()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -538,7 +538,7 @@ public final class CSListMonitor: NSObject, CoreStoreObjectiveCType {
|
||||
@nonobjc
|
||||
public required init<T: NSManagedObject>(_ swiftValue: ListMonitor<T>) {
|
||||
|
||||
self.bridgeToSwift = swiftValue.upcast()
|
||||
self.bridgeToSwift = swiftValue.downcast()
|
||||
super.init()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,5 +177,8 @@ extension MigrationResult: CoreStoreSwiftType {
|
||||
|
||||
// MARK: CoreStoreSwiftType
|
||||
|
||||
public typealias ObjectiveCType = CSMigrationResult
|
||||
public var bridgeToObjectiveC: CSMigrationResult {
|
||||
|
||||
return CSMigrationResult(self)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,5 +123,8 @@ extension MigrationType: CoreStoreSwiftType {
|
||||
|
||||
// MARK: CoreStoreSwiftType
|
||||
|
||||
public typealias ObjectiveCType = CSMigrationType
|
||||
public var bridgeToObjectiveC: CSMigrationType {
|
||||
|
||||
return CSMigrationType(self)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ public final class CSObjectMonitor: NSObject, CoreStoreObjectiveCType {
|
||||
@nonobjc
|
||||
public required init<T: NSManagedObject>(_ swiftValue: ObjectMonitor<T>) {
|
||||
|
||||
self.bridgeToSwift = swiftValue.upcast()
|
||||
self.bridgeToSwift = swiftValue.downcast()
|
||||
super.init()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,5 +126,8 @@ extension OrderBy: CoreStoreSwiftType {
|
||||
|
||||
// MARK: CoreStoreSwiftType
|
||||
|
||||
public typealias ObjectiveCType = CSOrderBy
|
||||
public var bridgeToObjectiveC: CSOrderBy {
|
||||
|
||||
return CSOrderBy(self)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,5 +203,8 @@ extension SQLiteStore: CoreStoreSwiftType {
|
||||
|
||||
// MARK: CoreStoreSwiftType
|
||||
|
||||
public typealias ObjectiveCType = CSSQLiteStore
|
||||
public var bridgeToObjectiveC: CSSQLiteStore {
|
||||
|
||||
return CSSQLiteStore(self)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,5 +177,8 @@ extension SaveResult: CoreStoreSwiftType {
|
||||
|
||||
// MARK: CoreStoreSwiftType
|
||||
|
||||
public typealias ObjectiveCType = CSSaveResult
|
||||
public var bridgeToObjectiveC: CSSaveResult {
|
||||
|
||||
return CSSaveResult(self)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,7 +91,10 @@ extension SectionBy: CoreStoreSwiftType {
|
||||
|
||||
// MARK: CoreStoreSwiftType
|
||||
|
||||
public typealias ObjectiveCType = CSSectionBy
|
||||
public var bridgeToObjectiveC: CSSectionBy {
|
||||
|
||||
return CSSectionBy(self)
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -192,7 +192,10 @@ extension SelectTerm: CoreStoreSwiftType {
|
||||
|
||||
// MARK: CoreStoreSwiftType
|
||||
|
||||
public typealias ObjectiveCType = CSSelectTerm
|
||||
public var bridgeToObjectiveC: CSSelectTerm {
|
||||
|
||||
return CSSelectTerm(self)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -181,8 +181,6 @@ extension SetupResult where T: CoreStoreSwiftType, T.ObjectiveCType: CSStorageIn
|
||||
|
||||
// MARK: CoreStoreSwiftType
|
||||
|
||||
public typealias ObjectiveCType = CSSetupResult
|
||||
|
||||
public var bridgeToObjectiveC: CSSetupResult {
|
||||
|
||||
return CSSetupResult(self)
|
||||
|
||||
@@ -167,5 +167,8 @@ extension SynchronousDataTransaction: CoreStoreSwiftType {
|
||||
|
||||
// MARK: CoreStoreSwiftType
|
||||
|
||||
public typealias ObjectiveCType = CSSynchronousDataTransaction
|
||||
public var bridgeToObjectiveC: CSSynchronousDataTransaction {
|
||||
|
||||
return CSSynchronousDataTransaction(self)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,5 +94,8 @@ extension Tweak: CoreStoreSwiftType {
|
||||
|
||||
// MARK: CoreStoreSwiftType
|
||||
|
||||
public typealias ObjectiveCType = CSTweak
|
||||
public var bridgeToObjectiveC: CSTweak {
|
||||
|
||||
return CSTweak(self)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -197,5 +197,8 @@ extension UnsafeDataTransaction: CoreStoreSwiftType {
|
||||
|
||||
// MARK: CoreStoreSwiftType
|
||||
|
||||
public typealias ObjectiveCType = CSUnsafeDataTransaction
|
||||
public var bridgeToObjectiveC: CSUnsafeDataTransaction {
|
||||
|
||||
return CSUnsafeDataTransaction(self)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,5 +163,8 @@ extension Where: CoreStoreSwiftType {
|
||||
|
||||
// MARK: CoreStoreSwiftType
|
||||
|
||||
public typealias ObjectiveCType = CSWhere
|
||||
public var bridgeToObjectiveC: CSWhere {
|
||||
|
||||
return CSWhere(self)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,28 +68,20 @@ public protocol CoreStoreSwiftType {
|
||||
var bridgeToObjectiveC: ObjectiveCType { get }
|
||||
}
|
||||
|
||||
public extension CoreStoreSwiftType where ObjectiveCType: CoreStoreObjectiveCType, Self == ObjectiveCType.SwiftType {
|
||||
|
||||
public var bridgeToObjectiveC: ObjectiveCType {
|
||||
|
||||
return ObjectiveCType(self)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Internal
|
||||
|
||||
internal func bridge<T: CoreStoreSwiftType>(_ closure: () -> T) -> T.ObjectiveCType where T.ObjectiveCType: CoreStoreObjectiveCType, T == T.ObjectiveCType.SwiftType {
|
||||
internal func bridge<T: CoreStoreSwiftType>(_ closure: () -> T) -> T.ObjectiveCType {
|
||||
|
||||
return closure().bridgeToObjectiveC
|
||||
}
|
||||
|
||||
internal func bridge<T: CoreStoreSwiftType>(_ closure: () -> T?) -> T.ObjectiveCType? where T.ObjectiveCType: CoreStoreObjectiveCType, T == T.ObjectiveCType.SwiftType {
|
||||
internal func bridge<T: CoreStoreSwiftType>(_ closure: () -> T?) -> T.ObjectiveCType? {
|
||||
|
||||
return closure()?.bridgeToObjectiveC
|
||||
}
|
||||
|
||||
internal func bridge<T: CoreStoreSwiftType>(_ closure: () throws -> T) throws -> T.ObjectiveCType where T.ObjectiveCType: CoreStoreObjectiveCType, T == T.ObjectiveCType.SwiftType {
|
||||
internal func bridge<T: CoreStoreSwiftType>(_ closure: () throws -> T) throws -> T.ObjectiveCType {
|
||||
|
||||
do {
|
||||
|
||||
|
||||
@@ -88,7 +88,7 @@ fileprivate func createFRC(fromContext context: NSManagedObjectContext, from: CS
|
||||
let controller = CoreStoreFetchedResultsController(
|
||||
context: context,
|
||||
fetchRequest: CoreStoreFetchRequest().dynamicCast(),
|
||||
from: from?.bridgeToSwift.upcast(),
|
||||
from: from?.bridgeToSwift.downcast(),
|
||||
sectionBy: sectionBy?.bridgeToSwift,
|
||||
applyFetchClauses: { (fetchRequest) in
|
||||
|
||||
|
||||
@@ -675,9 +675,9 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
|
||||
)
|
||||
}
|
||||
|
||||
internal func upcast() -> ListMonitor<NSManagedObject> {
|
||||
internal func downcast() -> ListMonitor<NSManagedObject> {
|
||||
|
||||
return unsafeBitCast(self, to: ListMonitor<NSManagedObject>.self)
|
||||
return unsafeDowncast(self, to: ListMonitor<NSManagedObject>.self)
|
||||
}
|
||||
|
||||
internal func registerChangeNotification(_ notificationKey: UnsafeRawPointer, name: Notification.Name, toObserver observer: AnyObject, callback: @escaping (_ monitor: ListMonitor<T>) -> Void) {
|
||||
|
||||
@@ -210,9 +210,9 @@ public final class ObjectMonitor<EntityType: NSManagedObject>: Equatable {
|
||||
cs_setAssociatedRetainedObject(nilValue, forKey: &self.didUpdateObjectKey, inObject: observer)
|
||||
}
|
||||
|
||||
internal func upcast() -> ObjectMonitor<NSManagedObject> {
|
||||
internal func downcast() -> ObjectMonitor<NSManagedObject> {
|
||||
|
||||
return unsafeBitCast(self, to: ObjectMonitor<NSManagedObject>.self)
|
||||
return unsafeDowncast(self, to: ObjectMonitor<NSManagedObject>.self)
|
||||
}
|
||||
|
||||
deinit {
|
||||
|
||||
@@ -59,6 +59,8 @@ public final class DataStack: Equatable {
|
||||
*/
|
||||
public required init(model: NSManagedObjectModel, migrationChain: MigrationChain = nil) {
|
||||
|
||||
_ = DataStack.isGloballyInitialized
|
||||
|
||||
CoreStore.assert(
|
||||
migrationChain.valid,
|
||||
"Invalid migration chain passed to the \(cs_typeName(DataStack.self)). Check that the model versions' order is correct and that no repetitions or ambiguities exist."
|
||||
@@ -499,6 +501,12 @@ public final class DataStack: Equatable {
|
||||
|
||||
// MARK: Private
|
||||
|
||||
private static let isGloballyInitialized: Bool = {
|
||||
|
||||
NSManagedObject.cs_swizzleMethodsForLogging()
|
||||
return true
|
||||
}()
|
||||
|
||||
private var configurationStoreMapping = [String: NSPersistentStore]()
|
||||
private var entityConfigurationsMapping = [String: Set<String>]()
|
||||
|
||||
|
||||
@@ -163,7 +163,7 @@ public struct Into<T: NSManagedObject>: Hashable {
|
||||
|
||||
internal let inferStoreIfPossible: Bool
|
||||
|
||||
internal func upcast() -> Into<NSManagedObject> {
|
||||
internal func downcast() -> Into<NSManagedObject> {
|
||||
|
||||
return Into<NSManagedObject>(
|
||||
entityClass: self.entityClass,
|
||||
|
||||
Reference in New Issue
Block a user