mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-03-20 16:44:08 +01:00
WIP: logging utilities
This commit is contained in:
@@ -57,14 +57,14 @@ public extension NSProgress {
|
||||
|
||||
get {
|
||||
|
||||
let object: ProgressObserver? = getAssociatedObjectForKey(&PropertyKeys.progressObserver, inObject: self)
|
||||
let object: ProgressObserver? = cs_getAssociatedObjectForKey(&PropertyKeys.progressObserver, inObject: self)
|
||||
if let observer = object {
|
||||
|
||||
return observer
|
||||
}
|
||||
|
||||
let observer = ProgressObserver(self)
|
||||
setAssociatedRetainedObject(
|
||||
cs_setAssociatedRetainedObject(
|
||||
observer,
|
||||
forKey: &PropertyKeys.progressObserver,
|
||||
inObject: self
|
||||
|
||||
@@ -32,7 +32,7 @@ import CoreData
|
||||
/**
|
||||
All errors thrown from CoreStore are expressed in `CoreStoreError` enum values.
|
||||
*/
|
||||
public enum CoreStoreError: ErrorType, CustomStringConvertible, CustomDebugStringConvertible, Hashable {
|
||||
public enum CoreStoreError: ErrorType, Hashable {
|
||||
|
||||
/**
|
||||
A failure occured because of an unknown error.
|
||||
@@ -89,23 +89,6 @@ public enum CoreStoreError: ErrorType, CustomStringConvertible, CustomDebugStrin
|
||||
}
|
||||
|
||||
|
||||
// MARK: CustomStringConvertible
|
||||
|
||||
public var description: String {
|
||||
|
||||
// TODO:
|
||||
return self.bridgeToObjectiveC.description
|
||||
}
|
||||
|
||||
|
||||
// MARK: CustomDebugStringConvertible
|
||||
|
||||
public var debugDescription: String {
|
||||
|
||||
return self.description
|
||||
}
|
||||
|
||||
|
||||
// MARK: Hashable
|
||||
|
||||
public var hashValue: Int {
|
||||
|
||||
@@ -118,7 +118,7 @@ public extension BaseDataTransaction {
|
||||
|
||||
CoreStore.assert(
|
||||
self.isRunningInAllowedQueue(),
|
||||
"Attempted to fetch from a \(typeName(self)) outside its designated queue."
|
||||
"Attempted to fetch from a \(cs_typeName(self)) outside its designated queue."
|
||||
)
|
||||
return self.context.fetchOne(from, fetchClauses)
|
||||
}
|
||||
@@ -148,7 +148,7 @@ public extension BaseDataTransaction {
|
||||
|
||||
CoreStore.assert(
|
||||
self.isRunningInAllowedQueue(),
|
||||
"Attempted to fetch from a \(typeName(self)) outside its designated queue."
|
||||
"Attempted to fetch from a \(cs_typeName(self)) outside its designated queue."
|
||||
)
|
||||
return self.context.fetchAll(from, fetchClauses)
|
||||
}
|
||||
@@ -178,7 +178,7 @@ public extension BaseDataTransaction {
|
||||
|
||||
CoreStore.assert(
|
||||
self.isRunningInAllowedQueue(),
|
||||
"Attempted to fetch from a \(typeName(self)) outside its designated queue."
|
||||
"Attempted to fetch from a \(cs_typeName(self)) outside its designated queue."
|
||||
)
|
||||
|
||||
return self.context.fetchCount(from, fetchClauses)
|
||||
@@ -209,7 +209,7 @@ public extension BaseDataTransaction {
|
||||
|
||||
CoreStore.assert(
|
||||
self.isRunningInAllowedQueue(),
|
||||
"Attempted to fetch from a \(typeName(self)) outside its designated queue."
|
||||
"Attempted to fetch from a \(cs_typeName(self)) outside its designated queue."
|
||||
)
|
||||
return self.context.fetchObjectID(from, fetchClauses)
|
||||
}
|
||||
@@ -239,7 +239,7 @@ public extension BaseDataTransaction {
|
||||
|
||||
CoreStore.assert(
|
||||
self.isRunningInAllowedQueue(),
|
||||
"Attempted to fetch from a \(typeName(self)) outside its designated queue."
|
||||
"Attempted to fetch from a \(cs_typeName(self)) outside its designated queue."
|
||||
)
|
||||
return self.context.fetchObjectIDs(from, fetchClauses)
|
||||
}
|
||||
@@ -255,7 +255,7 @@ public extension BaseDataTransaction {
|
||||
|
||||
CoreStore.assert(
|
||||
self.isRunningInAllowedQueue(),
|
||||
"Attempted to delete from a \(typeName(self)) outside its designated queue."
|
||||
"Attempted to delete from a \(cs_typeName(self)) outside its designated queue."
|
||||
)
|
||||
|
||||
return self.context.deleteAll(from, deleteClauses)
|
||||
@@ -272,7 +272,7 @@ public extension BaseDataTransaction {
|
||||
|
||||
CoreStore.assert(
|
||||
self.isRunningInAllowedQueue(),
|
||||
"Attempted to delete from a \(typeName(self)) outside its designated queue."
|
||||
"Attempted to delete from a \(cs_typeName(self)) outside its designated queue."
|
||||
)
|
||||
|
||||
return self.context.deleteAll(from, deleteClauses)
|
||||
@@ -293,7 +293,7 @@ public extension BaseDataTransaction {
|
||||
|
||||
CoreStore.assert(
|
||||
self.isRunningInAllowedQueue(),
|
||||
"Attempted to query from a \(typeName(self)) outside its designated queue."
|
||||
"Attempted to query from a \(cs_typeName(self)) outside its designated queue."
|
||||
)
|
||||
|
||||
return self.context.queryValue(from, selectClause, queryClauses)
|
||||
@@ -314,7 +314,7 @@ public extension BaseDataTransaction {
|
||||
|
||||
CoreStore.assert(
|
||||
self.isRunningInAllowedQueue(),
|
||||
"Attempted to query from a \(typeName(self)) outside its designated queue."
|
||||
"Attempted to query from a \(cs_typeName(self)) outside its designated queue."
|
||||
)
|
||||
|
||||
return self.context.queryValue(from, selectClause, queryClauses)
|
||||
@@ -335,7 +335,7 @@ public extension BaseDataTransaction {
|
||||
|
||||
CoreStore.assert(
|
||||
self.isRunningInAllowedQueue(),
|
||||
"Attempted to query from a \(typeName(self)) outside its designated queue."
|
||||
"Attempted to query from a \(cs_typeName(self)) outside its designated queue."
|
||||
)
|
||||
|
||||
return self.context.queryAttributes(from, selectClause, queryClauses)
|
||||
@@ -356,7 +356,7 @@ public extension BaseDataTransaction {
|
||||
|
||||
CoreStore.assert(
|
||||
self.isRunningInAllowedQueue(),
|
||||
"Attempted to query from a \(typeName(self)) outside its designated queue."
|
||||
"Attempted to query from a \(cs_typeName(self)) outside its designated queue."
|
||||
)
|
||||
|
||||
return self.context.queryAttributes(from, selectClause, queryClauses)
|
||||
|
||||
@@ -74,7 +74,7 @@ public struct GroupBy: QueryClause, Hashable {
|
||||
|
||||
CoreStore.log(
|
||||
.Warning,
|
||||
message: "An existing \"propertiesToGroupBy\" for the \(typeName(NSFetchRequest)) was overwritten by \(typeName(self)) query clause."
|
||||
message: "An existing \"propertiesToGroupBy\" for the \(cs_typeName(NSFetchRequest)) was overwritten by \(cs_typeName(self)) query clause."
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -141,7 +141,7 @@ public struct OrderBy: FetchClause, QueryClause, DeleteClause, Hashable {
|
||||
|
||||
CoreStore.log(
|
||||
.Warning,
|
||||
message: "Existing sortDescriptors for the \(typeName(NSFetchRequest)) was overwritten by \(typeName(self)) query clause."
|
||||
message: "Existing sortDescriptors for the \(cs_typeName(NSFetchRequest)) was overwritten by \(cs_typeName(self)) query clause."
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -722,7 +722,7 @@ internal extension CollectionType where Generator.Element == SelectTerm {
|
||||
|
||||
CoreStore.log(
|
||||
.Warning,
|
||||
message: "The property \"\(keyPath)\" does not exist in entity \(typeName(entityDescription.managedObjectClassName)) and will be ignored by \(typeName(owner)) query clause."
|
||||
message: "The property \"\(keyPath)\" does not exist in entity \(cs_typeName(entityDescription.managedObjectClassName)) and will be ignored by \(cs_typeName(owner)) query clause."
|
||||
)
|
||||
}
|
||||
|
||||
@@ -750,7 +750,7 @@ internal extension CollectionType where Generator.Element == SelectTerm {
|
||||
|
||||
CoreStore.log(
|
||||
.Warning,
|
||||
message: "The attribute \"\(keyPath)\" does not exist in entity \(typeName(entityDescription.managedObjectClassName)) and will be ignored by \(typeName(owner)) query clause."
|
||||
message: "The attribute \"\(keyPath)\" does not exist in entity \(cs_typeName(entityDescription.managedObjectClassName)) and will be ignored by \(cs_typeName(owner)) query clause."
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -146,7 +146,7 @@ public struct Where: FetchClause, QueryClause, DeleteClause, Hashable {
|
||||
|
||||
CoreStore.log(
|
||||
.Warning,
|
||||
message: "An existing predicate for the \(typeName(NSFetchRequest)) was overwritten by \(typeName(self)) query clause."
|
||||
message: "An existing predicate for the \(cs_typeName(NSFetchRequest)) was overwritten by \(cs_typeName(self)) query clause."
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ public extension DataStack {
|
||||
|
||||
CoreStore.assert(
|
||||
NSThread.isMainThread(),
|
||||
"Attempted to fetch from a \(typeName(self)) outside the main thread."
|
||||
"Attempted to fetch from a \(cs_typeName(self)) outside the main thread."
|
||||
)
|
||||
return self.mainContext.fetchOne(from, fetchClauses)
|
||||
}
|
||||
@@ -125,7 +125,7 @@ public extension DataStack {
|
||||
|
||||
CoreStore.assert(
|
||||
NSThread.isMainThread(),
|
||||
"Attempted to fetch from a \(typeName(self)) outside the main thread."
|
||||
"Attempted to fetch from a \(cs_typeName(self)) outside the main thread."
|
||||
)
|
||||
return self.mainContext.fetchOne(from, fetchClauses)
|
||||
}
|
||||
@@ -142,7 +142,7 @@ public extension DataStack {
|
||||
|
||||
CoreStore.assert(
|
||||
NSThread.isMainThread(),
|
||||
"Attempted to fetch from a \(typeName(self)) outside the main thread."
|
||||
"Attempted to fetch from a \(cs_typeName(self)) outside the main thread."
|
||||
)
|
||||
return self.mainContext.fetchAll(from, fetchClauses)
|
||||
}
|
||||
@@ -159,7 +159,7 @@ public extension DataStack {
|
||||
|
||||
CoreStore.assert(
|
||||
NSThread.isMainThread(),
|
||||
"Attempted to fetch from a \(typeName(self)) outside the main thread."
|
||||
"Attempted to fetch from a \(cs_typeName(self)) outside the main thread."
|
||||
)
|
||||
return self.mainContext.fetchAll(from, fetchClauses)
|
||||
}
|
||||
@@ -176,7 +176,7 @@ public extension DataStack {
|
||||
|
||||
CoreStore.assert(
|
||||
NSThread.isMainThread(),
|
||||
"Attempted to fetch from a \(typeName(self)) outside the main thread."
|
||||
"Attempted to fetch from a \(cs_typeName(self)) outside the main thread."
|
||||
)
|
||||
return self.mainContext.fetchCount(from, fetchClauses)
|
||||
}
|
||||
@@ -193,7 +193,7 @@ public extension DataStack {
|
||||
|
||||
CoreStore.assert(
|
||||
NSThread.isMainThread(),
|
||||
"Attempted to fetch from a \(typeName(self)) outside the main thread."
|
||||
"Attempted to fetch from a \(cs_typeName(self)) outside the main thread."
|
||||
)
|
||||
return self.mainContext.fetchCount(from, fetchClauses)
|
||||
}
|
||||
@@ -210,7 +210,7 @@ public extension DataStack {
|
||||
|
||||
CoreStore.assert(
|
||||
NSThread.isMainThread(),
|
||||
"Attempted to fetch from a \(typeName(self)) outside the main thread."
|
||||
"Attempted to fetch from a \(cs_typeName(self)) outside the main thread."
|
||||
)
|
||||
return self.mainContext.fetchObjectID(from, fetchClauses)
|
||||
}
|
||||
@@ -227,7 +227,7 @@ public extension DataStack {
|
||||
|
||||
CoreStore.assert(
|
||||
NSThread.isMainThread(),
|
||||
"Attempted to fetch from a \(typeName(self)) outside the main thread."
|
||||
"Attempted to fetch from a \(cs_typeName(self)) outside the main thread."
|
||||
)
|
||||
return self.mainContext.fetchObjectID(from, fetchClauses)
|
||||
}
|
||||
@@ -244,7 +244,7 @@ public extension DataStack {
|
||||
|
||||
CoreStore.assert(
|
||||
NSThread.isMainThread(),
|
||||
"Attempted to fetch from a \(typeName(self)) outside the main thread."
|
||||
"Attempted to fetch from a \(cs_typeName(self)) outside the main thread."
|
||||
)
|
||||
return self.mainContext.fetchObjectIDs(from, fetchClauses)
|
||||
}
|
||||
@@ -261,7 +261,7 @@ public extension DataStack {
|
||||
|
||||
CoreStore.assert(
|
||||
NSThread.isMainThread(),
|
||||
"Attempted to fetch from a \(typeName(self)) outside the main thread."
|
||||
"Attempted to fetch from a \(cs_typeName(self)) outside the main thread."
|
||||
)
|
||||
return self.mainContext.fetchObjectIDs(from, fetchClauses)
|
||||
}
|
||||
@@ -281,7 +281,7 @@ public extension DataStack {
|
||||
|
||||
CoreStore.assert(
|
||||
NSThread.isMainThread(),
|
||||
"Attempted to query from a \(typeName(self)) outside the main thread."
|
||||
"Attempted to query from a \(cs_typeName(self)) outside the main thread."
|
||||
)
|
||||
return self.mainContext.queryValue(from, selectClause, queryClauses)
|
||||
}
|
||||
@@ -301,7 +301,7 @@ public extension DataStack {
|
||||
|
||||
CoreStore.assert(
|
||||
NSThread.isMainThread(),
|
||||
"Attempted to query from a \(typeName(self)) outside the main thread."
|
||||
"Attempted to query from a \(cs_typeName(self)) outside the main thread."
|
||||
)
|
||||
return self.mainContext.queryValue(from, selectClause, queryClauses)
|
||||
}
|
||||
@@ -321,7 +321,7 @@ public extension DataStack {
|
||||
|
||||
CoreStore.assert(
|
||||
NSThread.isMainThread(),
|
||||
"Attempted to query from a \(typeName(self)) outside the main thread."
|
||||
"Attempted to query from a \(cs_typeName(self)) outside the main thread."
|
||||
)
|
||||
return self.mainContext.queryAttributes(from, selectClause, queryClauses)
|
||||
}
|
||||
@@ -341,7 +341,7 @@ public extension DataStack {
|
||||
|
||||
CoreStore.assert(
|
||||
NSThread.isMainThread(),
|
||||
"Attempted to query from a \(typeName(self)) outside the main thread."
|
||||
"Attempted to query from a \(cs_typeName(self)) outside the main thread."
|
||||
)
|
||||
return self.mainContext.queryAttributes(from, selectClause, queryClauses)
|
||||
}
|
||||
|
||||
@@ -44,10 +44,10 @@ public extension BaseDataTransaction {
|
||||
|
||||
CoreStore.assert(
|
||||
self.isRunningInAllowedQueue(),
|
||||
"Attempted to import an object of type \(typeName(into.entityClass)) outside the transaction's designated queue."
|
||||
"Attempted to import an object of type \(cs_typeName(into.entityClass)) outside the transaction's designated queue."
|
||||
)
|
||||
|
||||
return try autoreleasepool {
|
||||
return try cs_autoreleasepool {
|
||||
|
||||
guard T.shouldInsertFromImportSource(source, inTransaction: self) else {
|
||||
|
||||
@@ -72,10 +72,10 @@ public extension BaseDataTransaction {
|
||||
|
||||
CoreStore.assert(
|
||||
self.isRunningInAllowedQueue(),
|
||||
"Attempted to import an object of type \(typeName(object)) outside the transaction's designated queue."
|
||||
"Attempted to import an object of type \(cs_typeName(object)) outside the transaction's designated queue."
|
||||
)
|
||||
|
||||
try autoreleasepool {
|
||||
try cs_autoreleasepool {
|
||||
|
||||
guard T.shouldInsertFromImportSource(source, inTransaction: self) else {
|
||||
|
||||
@@ -99,10 +99,10 @@ public extension BaseDataTransaction {
|
||||
|
||||
CoreStore.assert(
|
||||
self.isRunningInAllowedQueue(),
|
||||
"Attempted to import an object of type \(typeName(into.entityClass)) outside the transaction's designated queue."
|
||||
"Attempted to import an object of type \(cs_typeName(into.entityClass)) outside the transaction's designated queue."
|
||||
)
|
||||
|
||||
return try autoreleasepool {
|
||||
return try cs_autoreleasepool {
|
||||
|
||||
return try sourceArray.flatMap { (source) -> T? in
|
||||
|
||||
@@ -111,7 +111,7 @@ public extension BaseDataTransaction {
|
||||
return nil
|
||||
}
|
||||
|
||||
return try autoreleasepool {
|
||||
return try cs_autoreleasepool {
|
||||
|
||||
let object = self.create(into)
|
||||
try object.didInsertFromImportSource(source, inTransaction: self)
|
||||
@@ -134,10 +134,10 @@ public extension BaseDataTransaction {
|
||||
|
||||
CoreStore.assert(
|
||||
self.isRunningInAllowedQueue(),
|
||||
"Attempted to import an object of type \(typeName(into.entityClass)) outside the transaction's designated queue."
|
||||
"Attempted to import an object of type \(cs_typeName(into.entityClass)) outside the transaction's designated queue."
|
||||
)
|
||||
|
||||
return try autoreleasepool {
|
||||
return try cs_autoreleasepool {
|
||||
|
||||
let uniqueIDKeyPath = T.uniqueIDKeyPath
|
||||
guard let uniqueIDValue = try T.uniqueIDFromImportSource(source, inTransaction: self) else {
|
||||
@@ -185,13 +185,13 @@ public extension BaseDataTransaction {
|
||||
|
||||
CoreStore.assert(
|
||||
self.isRunningInAllowedQueue(),
|
||||
"Attempted to import an object of type \(typeName(into.entityClass)) outside the transaction's designated queue."
|
||||
"Attempted to import an object of type \(cs_typeName(into.entityClass)) outside the transaction's designated queue."
|
||||
)
|
||||
|
||||
return try autoreleasepool {
|
||||
return try cs_autoreleasepool {
|
||||
|
||||
var mapping = Dictionary<T.UniqueIDType, T.ImportSource>()
|
||||
let sortedIDs = try autoreleasepool {
|
||||
let sortedIDs = try cs_autoreleasepool {
|
||||
|
||||
return try sourceArray.flatMap { (source) -> T.UniqueIDType? in
|
||||
|
||||
@@ -205,12 +205,12 @@ public extension BaseDataTransaction {
|
||||
}
|
||||
}
|
||||
|
||||
mapping = try autoreleasepool { try preProcess(mapping: mapping) }
|
||||
mapping = try cs_autoreleasepool { try preProcess(mapping: mapping) }
|
||||
|
||||
var objects = Dictionary<T.UniqueIDType, T>()
|
||||
for object in self.fetchAll(From(T), Where(T.uniqueIDKeyPath, isMemberOf: mapping.keys)) ?? [] {
|
||||
|
||||
try autoreleasepool {
|
||||
try cs_autoreleasepool {
|
||||
|
||||
let uniqueIDValue = object.uniqueIDValue
|
||||
|
||||
@@ -227,7 +227,7 @@ public extension BaseDataTransaction {
|
||||
|
||||
for (uniqueIDValue, source) in mapping {
|
||||
|
||||
try autoreleasepool {
|
||||
try cs_autoreleasepool {
|
||||
|
||||
guard T.shouldInsertFromImportSource(source, inTransaction: self) else {
|
||||
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
//
|
||||
// NSObject+CoreStore.swift
|
||||
// CoreStore
|
||||
//
|
||||
// Copyright © 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 func getAssociatedObjectForKey<T: AnyObject>(key: UnsafePointer<Void>, inObject object: AnyObject) -> T? {
|
||||
|
||||
switch objc_getAssociatedObject(object, key) {
|
||||
|
||||
case let associatedObject as T:
|
||||
return associatedObject
|
||||
|
||||
case let associatedObject as WeakObject:
|
||||
return associatedObject.object as? T
|
||||
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
internal func setAssociatedRetainedObject<T: AnyObject>(associatedObject: T?, forKey key: UnsafePointer<Void>, inObject object: AnyObject) {
|
||||
|
||||
objc_setAssociatedObject(object, key, associatedObject, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
|
||||
}
|
||||
|
||||
internal func setAssociatedCopiedObject<T: AnyObject>(associatedObject: T?, forKey key: UnsafePointer<Void>, inObject object: AnyObject) {
|
||||
|
||||
objc_setAssociatedObject(object, key, associatedObject, .OBJC_ASSOCIATION_COPY_NONATOMIC)
|
||||
}
|
||||
|
||||
internal func setAssociatedAssignedObject<T: AnyObject>(associatedObject: T?, forKey key: UnsafePointer<Void>, inObject object: AnyObject) {
|
||||
|
||||
objc_setAssociatedObject(object, key, associatedObject, .OBJC_ASSOCIATION_ASSIGN)
|
||||
}
|
||||
|
||||
internal func setAssociatedWeakObject<T: AnyObject>(associatedObject: T?, forKey key: UnsafePointer<Void>, inObject object: AnyObject) {
|
||||
|
||||
if let associatedObject = associatedObject {
|
||||
|
||||
objc_setAssociatedObject(object, key, WeakObject(associatedObject), .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
|
||||
}
|
||||
else {
|
||||
|
||||
objc_setAssociatedObject(object, key, nil, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
|
||||
}
|
||||
}
|
||||
@@ -39,5 +39,6 @@ internal final class CoreStoreFetchRequest: NSFetchRequest {
|
||||
set { self.safeAffectedStores = newValue }
|
||||
}
|
||||
|
||||
@nonobjc
|
||||
private var safeAffectedStores: [NSPersistentStore]?
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ internal final class CoreStoreFetchedResultsController: NSFetchedResultsControll
|
||||
|
||||
// MARK: Internal
|
||||
|
||||
@nonobjc
|
||||
internal convenience init<T: NSManagedObject>(dataStack: DataStack, fetchRequest: NSFetchRequest, from: From<T>? = nil, sectionBy: SectionBy? = nil, applyFetchClauses: (fetchRequest: NSFetchRequest) -> Void) {
|
||||
|
||||
self.init(
|
||||
@@ -45,6 +46,7 @@ internal final class CoreStoreFetchedResultsController: NSFetchedResultsControll
|
||||
)
|
||||
}
|
||||
|
||||
@nonobjc
|
||||
internal init<T: NSManagedObject>(context: NSManagedObjectContext, fetchRequest: NSFetchRequest, from: From<T>? = nil, sectionBy: SectionBy? = nil, applyFetchClauses: (fetchRequest: NSFetchRequest) -> Void) {
|
||||
|
||||
from?.applyToFetchRequest(fetchRequest, context: context, applyAffectedStores: false)
|
||||
@@ -61,7 +63,7 @@ internal final class CoreStoreFetchedResultsController: NSFetchedResultsControll
|
||||
|
||||
guard let from = (fetchRequest.entity.flatMap { $0.managedObjectClassName }).flatMap(NSClassFromString).flatMap(From.init) else {
|
||||
|
||||
fatalError("Attempted to create an \(typeName(NSFetchedResultsController)) without a From clause or an NSEntityDescription.")
|
||||
fatalError("Attempted to create an \(cs_typeName(NSFetchedResultsController)) without a From clause or an NSEntityDescription.")
|
||||
}
|
||||
|
||||
self.reapplyAffectedStores = { fetchRequest, context in
|
||||
@@ -78,13 +80,14 @@ internal final class CoreStoreFetchedResultsController: NSFetchedResultsControll
|
||||
)
|
||||
}
|
||||
|
||||
@nonobjc
|
||||
internal func performFetchFromSpecifiedStores() throws {
|
||||
|
||||
if !self.reapplyAffectedStores(fetchRequest: self.fetchRequest, context: self.managedObjectContext) {
|
||||
|
||||
CoreStore.log(
|
||||
.Warning,
|
||||
message: "Attempted to perform a fetch on an \(typeName(NSFetchedResultsController)) but could not find any persistent store for the entity \(typeName(self.fetchRequest.entityName))"
|
||||
message: "Attempted to perform a fetch on an \(cs_typeName(NSFetchedResultsController)) but could not find any persistent store for the entity \(cs_typeName(self.fetchRequest.entityName))"
|
||||
)
|
||||
}
|
||||
try self.performFetch()
|
||||
@@ -98,5 +101,6 @@ internal final class CoreStoreFetchedResultsController: NSFetchedResultsControll
|
||||
|
||||
// MARK: Private
|
||||
|
||||
@nonobjc
|
||||
private let reapplyAffectedStores: (fetchRequest: NSFetchRequest, context: NSManagedObjectContext) -> Bool
|
||||
}
|
||||
|
||||
@@ -51,9 +51,13 @@ internal final class FetchedResultsControllerDelegate: NSObject, NSFetchedResult
|
||||
|
||||
// MARK: Internal
|
||||
|
||||
@nonobjc
|
||||
internal var enabled = true
|
||||
|
||||
@nonobjc
|
||||
internal weak var handler: FetchedResultsControllerHandler?
|
||||
|
||||
@nonobjc
|
||||
internal weak var fetchedResultsController: NSFetchedResultsController? {
|
||||
|
||||
didSet {
|
||||
@@ -71,7 +75,8 @@ internal final class FetchedResultsControllerDelegate: NSObject, NSFetchedResult
|
||||
|
||||
// MARK: NSFetchedResultsControllerDelegate
|
||||
|
||||
@objc dynamic func controllerWillChangeContent(controller: NSFetchedResultsController) {
|
||||
@objc
|
||||
dynamic func controllerWillChangeContent(controller: NSFetchedResultsController) {
|
||||
|
||||
guard self.enabled else {
|
||||
|
||||
@@ -84,7 +89,8 @@ internal final class FetchedResultsControllerDelegate: NSObject, NSFetchedResult
|
||||
self.handler?.controllerWillChangeContent(controller)
|
||||
}
|
||||
|
||||
@objc dynamic func controllerDidChangeContent(controller: NSFetchedResultsController) {
|
||||
@objc
|
||||
dynamic func controllerDidChangeContent(controller: NSFetchedResultsController) {
|
||||
|
||||
guard self.enabled else {
|
||||
|
||||
@@ -94,7 +100,8 @@ internal final class FetchedResultsControllerDelegate: NSObject, NSFetchedResult
|
||||
self.handler?.controllerDidChangeContent(controller)
|
||||
}
|
||||
|
||||
@objc dynamic func controller(controller: NSFetchedResultsController, didChangeObject anObject: AnyObject, atIndexPath indexPath: NSIndexPath?, forChangeType type: NSFetchedResultsChangeType, newIndexPath: NSIndexPath?) {
|
||||
@objc
|
||||
dynamic func controller(controller: NSFetchedResultsController, didChangeObject anObject: AnyObject, atIndexPath indexPath: NSIndexPath?, forChangeType type: NSFetchedResultsChangeType, newIndexPath: NSIndexPath?) {
|
||||
|
||||
guard self.enabled else {
|
||||
|
||||
@@ -181,7 +188,8 @@ internal final class FetchedResultsControllerDelegate: NSObject, NSFetchedResult
|
||||
)
|
||||
}
|
||||
|
||||
@objc dynamic func controller(controller: NSFetchedResultsController, didChangeSection sectionInfo: NSFetchedResultsSectionInfo, atIndex sectionIndex: Int, forChangeType type: NSFetchedResultsChangeType) {
|
||||
@objc
|
||||
dynamic func controller(controller: NSFetchedResultsController, didChangeSection sectionInfo: NSFetchedResultsSectionInfo, atIndex sectionIndex: Int, forChangeType type: NSFetchedResultsChangeType) {
|
||||
|
||||
guard self.enabled else {
|
||||
|
||||
@@ -203,7 +211,8 @@ internal final class FetchedResultsControllerDelegate: NSObject, NSFetchedResult
|
||||
)
|
||||
}
|
||||
|
||||
@objc dynamic func controller(controller: NSFetchedResultsController, sectionIndexTitleForSectionName sectionName: String) -> String? {
|
||||
@objc
|
||||
dynamic func controller(controller: NSFetchedResultsController, sectionIndexTitleForSectionName sectionName: String) -> String? {
|
||||
|
||||
return self.handler?.controller(
|
||||
controller,
|
||||
@@ -214,6 +223,9 @@ internal final class FetchedResultsControllerDelegate: NSObject, NSFetchedResult
|
||||
|
||||
// MARK: Private
|
||||
|
||||
@nonobjc
|
||||
private var deletedSections = Set<Int>()
|
||||
|
||||
@nonobjc
|
||||
private var insertedSections = Set<Int>()
|
||||
}
|
||||
|
||||
@@ -25,10 +25,18 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
internal func autoreleasepool<T>(@noescape closure: () -> T) -> T {
|
||||
|
||||
// MARK: - Custom AutoreleasePool
|
||||
|
||||
internal func cs_autoreleasepool(@noescape closure: () -> Void) {
|
||||
|
||||
autoreleasepool(closure)
|
||||
}
|
||||
|
||||
internal func cs_autoreleasepool<T>(@noescape closure: () -> T) -> T {
|
||||
|
||||
var closureValue: T!
|
||||
ObjectiveC.autoreleasepool {
|
||||
autoreleasepool {
|
||||
|
||||
closureValue = closure()
|
||||
}
|
||||
@@ -36,11 +44,11 @@ internal func autoreleasepool<T>(@noescape closure: () -> T) -> T {
|
||||
return closureValue
|
||||
}
|
||||
|
||||
internal func autoreleasepool<T>(@noescape closure: () throws -> T) throws -> T {
|
||||
internal func cs_autoreleasepool<T>(@noescape closure: () throws -> T) throws -> T {
|
||||
|
||||
var closureValue: T!
|
||||
var closureError: ErrorType?
|
||||
ObjectiveC.autoreleasepool {
|
||||
autoreleasepool {
|
||||
|
||||
do {
|
||||
|
||||
@@ -59,10 +67,10 @@ internal func autoreleasepool<T>(@noescape closure: () throws -> T) throws -> T
|
||||
return closureValue
|
||||
}
|
||||
|
||||
internal func autoreleasepool(@noescape closure: () throws -> Void) throws {
|
||||
internal func cs_autoreleasepool(@noescape closure: () throws -> Void) throws {
|
||||
|
||||
var closureError: ErrorType?
|
||||
ObjectiveC.autoreleasepool {
|
||||
autoreleasepool {
|
||||
|
||||
do {
|
||||
|
||||
@@ -79,3 +87,63 @@ internal func autoreleasepool(@noescape closure: () throws -> Void) throws {
|
||||
throw closureError
|
||||
}
|
||||
}
|
||||
|
||||
internal func cs_getAssociatedObjectForKey<T: AnyObject>(key: UnsafePointer<Void>, inObject object: AnyObject) -> T? {
|
||||
|
||||
switch objc_getAssociatedObject(object, key) {
|
||||
|
||||
case let associatedObject as T:
|
||||
return associatedObject
|
||||
|
||||
case let associatedObject as WeakObject:
|
||||
return associatedObject.object as? T
|
||||
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
internal func cs_setAssociatedRetainedObject<T: AnyObject>(associatedObject: T?, forKey key: UnsafePointer<Void>, inObject object: AnyObject) {
|
||||
|
||||
objc_setAssociatedObject(object, key, associatedObject, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
|
||||
}
|
||||
|
||||
internal func cs_setAssociatedCopiedObject<T: AnyObject>(associatedObject: T?, forKey key: UnsafePointer<Void>, inObject object: AnyObject) {
|
||||
|
||||
objc_setAssociatedObject(object, key, associatedObject, .OBJC_ASSOCIATION_COPY_NONATOMIC)
|
||||
}
|
||||
|
||||
internal func cs_setAssociatedWeakObject<T: AnyObject>(associatedObject: T?, forKey key: UnsafePointer<Void>, inObject object: AnyObject) {
|
||||
|
||||
if let associatedObject = associatedObject {
|
||||
|
||||
objc_setAssociatedObject(object, key, WeakObject(associatedObject), .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
|
||||
}
|
||||
else {
|
||||
|
||||
objc_setAssociatedObject(object, key, nil, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: Printing Utilities
|
||||
|
||||
internal func cs_typeName<T>(value: T) -> String {
|
||||
|
||||
return "'\(String(reflecting: value.dynamicType))'"
|
||||
}
|
||||
|
||||
internal func cs_typeName<T>(value: T.Type) -> String {
|
||||
|
||||
return "'\(value)'"
|
||||
}
|
||||
|
||||
internal func cs_typeName(value: AnyClass) -> String {
|
||||
|
||||
return "'\(value)'"
|
||||
}
|
||||
|
||||
internal func cs_typeName(name: String?) -> String {
|
||||
|
||||
return "<\(name ?? "unknown")>"
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ internal extension NSManagedObjectContext {
|
||||
|
||||
get {
|
||||
|
||||
let number: NSNumber? = getAssociatedObjectForKey(
|
||||
let number: NSNumber? = cs_getAssociatedObjectForKey(
|
||||
&PropertyKeys.shouldCascadeSavesToParent,
|
||||
inObject: self
|
||||
)
|
||||
@@ -49,7 +49,7 @@ internal extension NSManagedObjectContext {
|
||||
}
|
||||
set {
|
||||
|
||||
setAssociatedCopiedObject(
|
||||
cs_setAssociatedCopiedObject(
|
||||
NSNumber(bool: newValue),
|
||||
forKey: &PropertyKeys.shouldCascadeSavesToParent,
|
||||
inObject: self
|
||||
@@ -132,14 +132,14 @@ internal extension NSManagedObjectContext {
|
||||
|
||||
get {
|
||||
|
||||
return getAssociatedObjectForKey(
|
||||
return cs_getAssociatedObjectForKey(
|
||||
&PropertyKeys.observerForWillSaveNotification,
|
||||
inObject: self
|
||||
)
|
||||
}
|
||||
set {
|
||||
|
||||
setAssociatedRetainedObject(
|
||||
cs_setAssociatedRetainedObject(
|
||||
newValue,
|
||||
forKey: &PropertyKeys.observerForWillSaveNotification,
|
||||
inObject: self
|
||||
|
||||
@@ -64,7 +64,7 @@ internal extension NSManagedObjectContext {
|
||||
|
||||
CoreStore.log(
|
||||
CoreStoreError(error),
|
||||
"Failed to load existing \(typeName(object)) in context."
|
||||
"Failed to load existing \(cs_typeName(object)) in context."
|
||||
)
|
||||
return nil
|
||||
}
|
||||
@@ -341,7 +341,7 @@ internal extension NSManagedObjectContext {
|
||||
var fetchError: ErrorType?
|
||||
self.performBlockAndWait {
|
||||
|
||||
autoreleasepool {
|
||||
cs_autoreleasepool {
|
||||
|
||||
do {
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ internal extension NSManagedObjectContext {
|
||||
return parentContext.parentStack
|
||||
}
|
||||
|
||||
return getAssociatedObjectForKey(&PropertyKeys.parentStack, inObject: self)
|
||||
return cs_getAssociatedObjectForKey(&PropertyKeys.parentStack, inObject: self)
|
||||
}
|
||||
set {
|
||||
|
||||
@@ -52,7 +52,7 @@ internal extension NSManagedObjectContext {
|
||||
return
|
||||
}
|
||||
|
||||
setAssociatedWeakObject(
|
||||
cs_setAssociatedWeakObject(
|
||||
newValue,
|
||||
forKey: &PropertyKeys.parentStack,
|
||||
inObject: self
|
||||
@@ -129,14 +129,14 @@ internal extension NSManagedObjectContext {
|
||||
|
||||
get {
|
||||
|
||||
return getAssociatedObjectForKey(
|
||||
return cs_getAssociatedObjectForKey(
|
||||
&PropertyKeys.observerForDidSaveNotification,
|
||||
inObject: self
|
||||
)
|
||||
}
|
||||
set {
|
||||
|
||||
setAssociatedRetainedObject(
|
||||
cs_setAssociatedRetainedObject(
|
||||
newValue,
|
||||
forKey: &PropertyKeys.observerForDidSaveNotification,
|
||||
inObject: self
|
||||
@@ -149,14 +149,14 @@ internal extension NSManagedObjectContext {
|
||||
|
||||
get {
|
||||
|
||||
return getAssociatedObjectForKey(
|
||||
return cs_getAssociatedObjectForKey(
|
||||
&PropertyKeys.observerForDidImportUbiquitousContentChangesNotification,
|
||||
inObject: self
|
||||
)
|
||||
}
|
||||
set {
|
||||
|
||||
setAssociatedRetainedObject(
|
||||
cs_setAssociatedRetainedObject(
|
||||
newValue,
|
||||
forKey: &PropertyKeys.observerForDidImportUbiquitousContentChangesNotification,
|
||||
inObject: self
|
||||
|
||||
@@ -41,14 +41,14 @@ internal extension NSManagedObjectContext {
|
||||
|
||||
get {
|
||||
|
||||
return getAssociatedObjectForKey(
|
||||
return cs_getAssociatedObjectForKey(
|
||||
&PropertyKeys.parentTransaction,
|
||||
inObject: self
|
||||
)
|
||||
}
|
||||
set {
|
||||
|
||||
setAssociatedWeakObject(
|
||||
cs_setAssociatedWeakObject(
|
||||
newValue,
|
||||
forKey: &PropertyKeys.parentTransaction,
|
||||
inObject: self
|
||||
@@ -100,7 +100,7 @@ internal extension NSManagedObjectContext {
|
||||
let saveError = CoreStoreError(error)
|
||||
CoreStore.log(
|
||||
saveError,
|
||||
"Failed to save \(typeName(NSManagedObjectContext))."
|
||||
"Failed to save \(cs_typeName(NSManagedObjectContext))."
|
||||
)
|
||||
result = SaveResult(saveError)
|
||||
return
|
||||
@@ -149,7 +149,7 @@ internal extension NSManagedObjectContext {
|
||||
let saveError = CoreStoreError(error)
|
||||
CoreStore.log(
|
||||
saveError,
|
||||
"Failed to save \(typeName(NSManagedObjectContext))."
|
||||
"Failed to save \(cs_typeName(NSManagedObjectContext))."
|
||||
)
|
||||
GCDQueue.Main.async {
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ internal extension NSManagedObjectModel {
|
||||
guard let versionInfo = NSDictionary(contentsOfURL: versionInfoPlistURL),
|
||||
let versionHashes = versionInfo["NSManagedObjectModel_VersionHashes"] as? [String: AnyObject] else {
|
||||
|
||||
fatalError("Could not load \(typeName(NSManagedObjectModel)) metadata from path \"\(versionInfoPlistURL)\".")
|
||||
fatalError("Could not load \(cs_typeName(NSManagedObjectModel)) metadata from path \"\(versionInfoPlistURL)\".")
|
||||
}
|
||||
|
||||
let modelVersions = Set(versionHashes.keys)
|
||||
@@ -106,7 +106,7 @@ internal extension NSManagedObjectModel {
|
||||
return rootModel
|
||||
}
|
||||
|
||||
fatalError("Could not create an \(typeName(NSManagedObjectModel)) from the model at URL \"\(modelFileURL)\".")
|
||||
fatalError("Could not create an \(cs_typeName(NSManagedObjectModel)) from the model at URL \"\(modelFileURL)\".")
|
||||
}
|
||||
|
||||
@nonobjc
|
||||
@@ -114,7 +114,7 @@ internal extension NSManagedObjectModel {
|
||||
|
||||
get {
|
||||
|
||||
let value: NSString? = getAssociatedObjectForKey(
|
||||
let value: NSString? = cs_getAssociatedObjectForKey(
|
||||
&PropertyKeys.currentModelVersion,
|
||||
inObject: self
|
||||
)
|
||||
@@ -122,7 +122,7 @@ internal extension NSManagedObjectModel {
|
||||
}
|
||||
set {
|
||||
|
||||
setAssociatedCopiedObject(
|
||||
cs_setAssociatedCopiedObject(
|
||||
newValue == nil ? nil : (newValue! as NSString),
|
||||
forKey: &PropertyKeys.currentModelVersion,
|
||||
inObject: self
|
||||
@@ -135,7 +135,7 @@ internal extension NSManagedObjectModel {
|
||||
|
||||
get {
|
||||
|
||||
let value: NSSet? = getAssociatedObjectForKey(
|
||||
let value: NSSet? = cs_getAssociatedObjectForKey(
|
||||
&PropertyKeys.modelVersions,
|
||||
inObject: self
|
||||
)
|
||||
@@ -143,7 +143,7 @@ internal extension NSManagedObjectModel {
|
||||
}
|
||||
set {
|
||||
|
||||
setAssociatedCopiedObject(
|
||||
cs_setAssociatedCopiedObject(
|
||||
newValue == nil ? nil : (newValue! as NSSet),
|
||||
forKey: &PropertyKeys.modelVersions,
|
||||
inObject: self
|
||||
@@ -235,7 +235,7 @@ internal extension NSManagedObjectModel {
|
||||
|
||||
get {
|
||||
|
||||
let value: NSURL? = getAssociatedObjectForKey(
|
||||
let value: NSURL? = cs_getAssociatedObjectForKey(
|
||||
&PropertyKeys.modelVersionFileURL,
|
||||
inObject: self
|
||||
)
|
||||
@@ -243,7 +243,7 @@ internal extension NSManagedObjectModel {
|
||||
}
|
||||
set {
|
||||
|
||||
setAssociatedCopiedObject(
|
||||
cs_setAssociatedCopiedObject(
|
||||
newValue,
|
||||
forKey: &PropertyKeys.modelVersionFileURL,
|
||||
inObject: self
|
||||
@@ -256,7 +256,7 @@ internal extension NSManagedObjectModel {
|
||||
|
||||
get {
|
||||
|
||||
if let mapping: NSDictionary = getAssociatedObjectForKey(&PropertyKeys.entityNameMapping, inObject: self) {
|
||||
if let mapping: NSDictionary = cs_getAssociatedObjectForKey(&PropertyKeys.entityNameMapping, inObject: self) {
|
||||
|
||||
return mapping as! [String: String]
|
||||
}
|
||||
@@ -272,7 +272,7 @@ internal extension NSManagedObjectModel {
|
||||
let className = $0.managedObjectClassName
|
||||
mapping[className] = entityName
|
||||
}
|
||||
setAssociatedCopiedObject(
|
||||
cs_setAssociatedCopiedObject(
|
||||
mapping as NSDictionary,
|
||||
forKey: &PropertyKeys.entityNameMapping,
|
||||
inObject: self
|
||||
|
||||
@@ -38,7 +38,7 @@ internal extension NSPersistentStore {
|
||||
|
||||
get {
|
||||
|
||||
let wrapper: StorageObject? = getAssociatedObjectForKey(
|
||||
let wrapper: StorageObject? = cs_getAssociatedObjectForKey(
|
||||
&PropertyKeys.storageInterface,
|
||||
inObject: self
|
||||
)
|
||||
@@ -46,7 +46,7 @@ internal extension NSPersistentStore {
|
||||
}
|
||||
set {
|
||||
|
||||
setAssociatedRetainedObject(
|
||||
cs_setAssociatedRetainedObject(
|
||||
StorageObject(newValue),
|
||||
forKey: &PropertyKeys.storageInterface,
|
||||
inObject: self
|
||||
@@ -70,8 +70,10 @@ private class StorageObject: NSObject {
|
||||
|
||||
// MARK: Private
|
||||
|
||||
@nonobjc
|
||||
private let storageInterface: StorageInterface?
|
||||
|
||||
@nonobjc
|
||||
private init(_ storage: StorageInterface?) {
|
||||
|
||||
self.storageInterface = storage
|
||||
|
||||
@@ -81,7 +81,7 @@ internal extension NSPersistentStoreCoordinator {
|
||||
else {
|
||||
|
||||
self.lock()
|
||||
autoreleasepool {
|
||||
cs_autoreleasepool {
|
||||
|
||||
result = closure()
|
||||
}
|
||||
@@ -129,7 +129,7 @@ internal extension NSPersistentStoreCoordinator {
|
||||
else {
|
||||
|
||||
self.lock()
|
||||
autoreleasepool {
|
||||
cs_autoreleasepool {
|
||||
|
||||
do {
|
||||
|
||||
|
||||
409
Sources/Logging/CoreStore+CustomDebugStringConvertible.swift
Normal file
409
Sources/Logging/CoreStore+CustomDebugStringConvertible.swift
Normal file
@@ -0,0 +1,409 @@
|
||||
//
|
||||
// CoreStore+CustomDebugStringConvertible.swift
|
||||
// CoreStore
|
||||
//
|
||||
// Copyright © 2016 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
|
||||
|
||||
|
||||
// MARK: - CoreStoreError
|
||||
|
||||
extension CoreStoreError: CustomDebugStringConvertible, IndentableDebugStringConvertible {
|
||||
|
||||
// MARK: CustomDebugStringConvertible
|
||||
|
||||
public var debugDescription: String {
|
||||
|
||||
return self.cs_dump()
|
||||
}
|
||||
|
||||
|
||||
// MARK: IndentableDebugStringConvertible
|
||||
|
||||
private var cs_dumpValue: String {
|
||||
|
||||
switch self {
|
||||
|
||||
case .Unknown: return ".Unknown"
|
||||
case .DifferentStorageExistsAtURL: return ".DifferentStorageExistsAtURL"
|
||||
case .MappingModelNotFound: return ".MappingModelNotFound"
|
||||
case .ProgressiveMigrationRequired: return ".ProgressiveMigrationRequired"
|
||||
case .InternalError: return ".InternalError"
|
||||
}
|
||||
}
|
||||
|
||||
private var cs_dumpInfo: DumpInfo {
|
||||
|
||||
var info: DumpInfo = [
|
||||
("_domain", self._domain.cs_dump()),
|
||||
("_code", self._code.cs_dump()),
|
||||
]
|
||||
switch self {
|
||||
|
||||
case .Unknown:
|
||||
break
|
||||
|
||||
case .DifferentStorageExistsAtURL(let existingPersistentStoreURL):
|
||||
info.append(("existingPersistentStoreURL", existingPersistentStoreURL.cs_dump()))
|
||||
|
||||
case .MappingModelNotFound(let localStoreURL, let targetModel, let targetModelVersion):
|
||||
info.append(("localStoreURL", localStoreURL.cs_dump()))
|
||||
info.append(("targetModel", targetModel.cs_dump()))
|
||||
info.append(("targetModelVersion", targetModelVersion.cs_dump()))
|
||||
|
||||
case .ProgressiveMigrationRequired(let localStoreURL):
|
||||
info.append(("localStoreURL", localStoreURL.cs_dump()))
|
||||
|
||||
case .InternalError(let NSError):
|
||||
info.append(("NSError", NSError.cs_dump()))
|
||||
}
|
||||
return info
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - InMemoryStore
|
||||
|
||||
extension InMemoryStore: CustomDebugStringConvertible, IndentableDebugStringConvertible {
|
||||
|
||||
// MARK: CustomDebugStringConvertible
|
||||
|
||||
public var debugDescription: String {
|
||||
|
||||
return self.cs_dump()
|
||||
}
|
||||
|
||||
|
||||
// MARK: IndentableDebugStringConvertible
|
||||
|
||||
private var cs_dumpInfo: DumpInfo {
|
||||
|
||||
return [
|
||||
("configuration", self.configuration),
|
||||
("storeOptions", self.storeOptions)
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - LocalStorageOptions
|
||||
|
||||
extension LocalStorageOptions: CustomDebugStringConvertible, IndentableDebugStringConvertible {
|
||||
|
||||
// MARK: CustomDebugStringConvertible
|
||||
|
||||
public var debugDescription: String {
|
||||
|
||||
return self.cs_dump()
|
||||
}
|
||||
|
||||
|
||||
// MARK: IndentableDebugStringConvertible
|
||||
|
||||
private var cs_dumpValue: String {
|
||||
|
||||
var flags = [String]()
|
||||
if self.contains(.RecreateStoreOnModelMismatch) {
|
||||
|
||||
flags.append(".RecreateStoreOnModelMismatch")
|
||||
}
|
||||
if self.contains(.PreventProgressiveMigration) {
|
||||
|
||||
flags.append(".PreventProgressiveMigration")
|
||||
}
|
||||
if self.contains(.AllowSynchronousLightweightMigration) {
|
||||
|
||||
flags.append(".AllowSynchronousLightweightMigration")
|
||||
}
|
||||
switch flags.count {
|
||||
|
||||
case 0:
|
||||
return "[.None]"
|
||||
|
||||
case 1:
|
||||
return "[.\(flags[0])]"
|
||||
|
||||
default:
|
||||
let description = "[\n" + flags.joinWithSeparator(",\n")
|
||||
return description.indent(1) + "\n]"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - SQLiteStore
|
||||
|
||||
extension SQLiteStore: CustomDebugStringConvertible, IndentableDebugStringConvertible {
|
||||
|
||||
// MARK: CustomDebugStringConvertible
|
||||
|
||||
public var debugDescription: String {
|
||||
|
||||
return self.cs_dump()
|
||||
}
|
||||
|
||||
|
||||
// MARK: IndentableDebugStringConvertible
|
||||
|
||||
private var cs_dumpInfo: DumpInfo {
|
||||
|
||||
return [
|
||||
("configuration", self.configuration),
|
||||
("storeOptions", self.storeOptions),
|
||||
("fileURL", self.fileURL),
|
||||
("mappingModelBundles", self.mappingModelBundles),
|
||||
("localStorageOptions", self.localStorageOptions)
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - LegacySQLiteStore
|
||||
|
||||
extension LegacySQLiteStore: CustomDebugStringConvertible, IndentableDebugStringConvertible {
|
||||
|
||||
// MARK: CustomDebugStringConvertible
|
||||
|
||||
public var debugDescription: String {
|
||||
|
||||
return self.cs_dump()
|
||||
}
|
||||
|
||||
|
||||
// MARK: IndentableDebugStringConvertible
|
||||
|
||||
private var cs_dumpInfo: DumpInfo {
|
||||
|
||||
return [
|
||||
("configuration", self.configuration),
|
||||
("storeOptions", self.storeOptions),
|
||||
("fileURL", self.fileURL),
|
||||
("mappingModelBundles", self.mappingModelBundles),
|
||||
("localStorageOptions", self.localStorageOptions)
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private typealias DumpInfo = [(key: String, value: IndentableDebugStringConvertible)]
|
||||
|
||||
private func formattedValue(any: Any) -> String {
|
||||
|
||||
if let any = any as? IndentableDebugStringConvertible {
|
||||
|
||||
return formattedValue(any)
|
||||
}
|
||||
return "\(any)"
|
||||
}
|
||||
|
||||
private func formattedValue(any: IndentableDebugStringConvertible) -> String {
|
||||
|
||||
return any.cs_dumpValue
|
||||
}
|
||||
|
||||
private protocol IndentableDebugStringConvertible {
|
||||
|
||||
static func cs_typeString() -> String
|
||||
|
||||
var cs_dumpValue: String { get }
|
||||
var cs_dumpInfo: DumpInfo { get }
|
||||
|
||||
func cs_dump() -> String
|
||||
}
|
||||
|
||||
private extension IndentableDebugStringConvertible {
|
||||
|
||||
private static func cs_typeString() -> String {
|
||||
|
||||
return String(reflecting: self)
|
||||
}
|
||||
|
||||
private var cs_dumpValue: String {
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
private var cs_dumpInfo: DumpInfo {
|
||||
|
||||
return []
|
||||
}
|
||||
|
||||
private func cs_dump() -> String {
|
||||
|
||||
let value = self.cs_dumpValue
|
||||
let info = self.cs_dumpInfo
|
||||
|
||||
var dump = "(\(self.dynamicType.cs_typeString()))"
|
||||
if !value.isEmpty {
|
||||
|
||||
dump.appendContentsOf(" \(value)")
|
||||
}
|
||||
if info.isEmpty {
|
||||
|
||||
return dump
|
||||
}
|
||||
else {
|
||||
|
||||
dump.appendContentsOf(" {")
|
||||
for (key, value) in info {
|
||||
|
||||
dump.appendContentsOf("\n.\(key) = \(formattedValue(value))")
|
||||
}
|
||||
return dump.indent(1) + "\n}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension String: IndentableDebugStringConvertible {
|
||||
|
||||
private var cs_dumpValue: String {
|
||||
|
||||
return "\"\(self)\""
|
||||
}
|
||||
}
|
||||
|
||||
extension NSURL: IndentableDebugStringConvertible {
|
||||
|
||||
private var cs_dumpValue: String {
|
||||
|
||||
return "\"\(self)\""
|
||||
}
|
||||
}
|
||||
|
||||
extension Int: IndentableDebugStringConvertible {
|
||||
|
||||
private var cs_dumpValue: String {
|
||||
|
||||
return "\(self)"
|
||||
}
|
||||
}
|
||||
|
||||
extension NSManagedObjectModel: IndentableDebugStringConvertible {
|
||||
|
||||
private var cs_dumpValue: String {
|
||||
|
||||
return "\(self)"
|
||||
}
|
||||
}
|
||||
|
||||
extension NSMappingModel: IndentableDebugStringConvertible {
|
||||
|
||||
private var cs_dumpValue: String {
|
||||
|
||||
return "\(self)"
|
||||
}
|
||||
}
|
||||
|
||||
extension NSError: IndentableDebugStringConvertible {
|
||||
|
||||
private var cs_dumpValue: String {
|
||||
|
||||
return "\(self)"
|
||||
}
|
||||
}
|
||||
|
||||
extension NSBundle: IndentableDebugStringConvertible {
|
||||
|
||||
private var cs_dumpValue: String {
|
||||
|
||||
return "\(self.bundleURL.lastPathComponent ?? "<unknown bundle URL>") (\(self.bundleIdentifier ?? "<unknown bundle identifier>"))"
|
||||
}
|
||||
}
|
||||
|
||||
extension Array: IndentableDebugStringConvertible {
|
||||
|
||||
private var cs_dumpValue: String {
|
||||
|
||||
var string = "\(self.count) items ["
|
||||
if self.isEmpty {
|
||||
|
||||
string.appendContentsOf("]")
|
||||
return string
|
||||
}
|
||||
else {
|
||||
|
||||
for (index, item) in self.enumerate() {
|
||||
|
||||
string.appendContentsOf("\n\(index) = \(formattedValue(item));")
|
||||
}
|
||||
return string.indent(1) + "\n]"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension Dictionary: IndentableDebugStringConvertible {
|
||||
|
||||
private var cs_dumpValue: String {
|
||||
|
||||
var string = "\(self.count) key-values ["
|
||||
if self.isEmpty {
|
||||
|
||||
string.appendContentsOf("]")
|
||||
return string
|
||||
}
|
||||
else {
|
||||
|
||||
for (key, value) in self {
|
||||
|
||||
string.appendContentsOf("\n\(formattedValue(key)) = \(formattedValue(value));")
|
||||
}
|
||||
return string.indent(1) + "\n]"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension Optional: IndentableDebugStringConvertible {
|
||||
|
||||
private var cs_dumpValue: String {
|
||||
|
||||
if let value = self {
|
||||
|
||||
return formattedValue(value)
|
||||
}
|
||||
return "nil"
|
||||
}
|
||||
}
|
||||
|
||||
private extension String {
|
||||
|
||||
private static func indention(level: Int = 1) -> String {
|
||||
|
||||
return String(count: level * 4, repeatedValue: Character(" "))
|
||||
}
|
||||
|
||||
private func trimSwiftModuleName() -> String {
|
||||
|
||||
if self.hasPrefix("Swift.") {
|
||||
|
||||
return self.substringFromIndex("Swift.".endIndex)
|
||||
}
|
||||
return self
|
||||
}
|
||||
|
||||
private func indent(level: Int) -> String {
|
||||
|
||||
return self.stringByReplacingOccurrencesOfString("\n", withString: "\n\(String.indention(level))")
|
||||
}
|
||||
}
|
||||
@@ -101,26 +101,3 @@ extension CoreStoreLogger {
|
||||
self.log(error: error.bridgeToSwift, message: message, fileName: fileName, lineNumber: lineNumber, functionName: functionName)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Utilities
|
||||
|
||||
internal func typeName<T>(value: T) -> String {
|
||||
|
||||
return "'\(String(reflecting: value.dynamicType))'"
|
||||
}
|
||||
|
||||
internal func typeName<T>(value: T.Type) -> String {
|
||||
|
||||
return "'\(value)'"
|
||||
}
|
||||
|
||||
internal func typeName(value: AnyClass) -> String {
|
||||
|
||||
return "'\(value)'"
|
||||
}
|
||||
|
||||
internal func typeName(name: String?) -> String {
|
||||
|
||||
return "<\(name ?? "unknown")>"
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ public extension DataStack {
|
||||
let storeError = CoreStoreError(error)
|
||||
CoreStore.log(
|
||||
storeError,
|
||||
"Failed to add \(typeName(storage)) to the stack."
|
||||
"Failed to add \(cs_typeName(storage)) to the stack."
|
||||
)
|
||||
GCDQueue.Main.async {
|
||||
|
||||
@@ -160,7 +160,7 @@ public extension DataStack {
|
||||
let fileURL = storage.fileURL
|
||||
CoreStore.assert(
|
||||
fileURL.fileURL,
|
||||
"The specified URL for the \(typeName(storage)) is invalid: \"\(fileURL)\""
|
||||
"The specified URL for the \(cs_typeName(storage)) is invalid: \"\(fileURL)\""
|
||||
)
|
||||
|
||||
return self.coordinator.performSynchronously {
|
||||
@@ -189,7 +189,7 @@ public extension DataStack {
|
||||
let error = CoreStoreError.DifferentStorageExistsAtURL(existingPersistentStoreURL: fileURL)
|
||||
CoreStore.log(
|
||||
error,
|
||||
"Failed to add \(typeName(storage)) at \"\(fileURL)\" because a different \(typeName(NSPersistentStore)) at that URL already exists."
|
||||
"Failed to add \(cs_typeName(storage)) at \"\(fileURL)\" because a different \(cs_typeName(NSPersistentStore)) at that URL already exists."
|
||||
)
|
||||
GCDQueue.Main.async {
|
||||
|
||||
@@ -281,7 +281,7 @@ public extension DataStack {
|
||||
let storeError = CoreStoreError(error)
|
||||
CoreStore.log(
|
||||
storeError,
|
||||
"Failed to load SQLite \(typeName(NSPersistentStore)) metadata."
|
||||
"Failed to load SQLite \(cs_typeName(NSPersistentStore)) metadata."
|
||||
)
|
||||
GCDQueue.Main.async {
|
||||
|
||||
@@ -345,7 +345,7 @@ public extension DataStack {
|
||||
let error = CoreStoreError.DifferentStorageExistsAtURL(existingPersistentStoreURL: cacheFileURL)
|
||||
CoreStore.log(
|
||||
error,
|
||||
"Failed to add \(typeName(storage)) at \"\(cacheFileURL)\" because a different \(typeName(NSPersistentStore)) at that URL already exists."
|
||||
"Failed to add \(cs_typeName(storage)) at \"\(cacheFileURL)\" because a different \(cs_typeName(NSPersistentStore)) at that URL already exists."
|
||||
)
|
||||
GCDQueue.Main.async {
|
||||
|
||||
@@ -418,7 +418,7 @@ public extension DataStack {
|
||||
let storeError = CoreStoreError(error)
|
||||
CoreStore.log(
|
||||
storeError,
|
||||
"Failed to load \(typeName(NSPersistentStore)) metadata."
|
||||
"Failed to load \(cs_typeName(NSPersistentStore)) metadata."
|
||||
)
|
||||
GCDQueue.Main.async {
|
||||
|
||||
@@ -445,7 +445,7 @@ public extension DataStack {
|
||||
|
||||
CoreStore.assert(
|
||||
self.persistentStoreForStorage(storage) == nil,
|
||||
"Attempted to migrate an already added \(typeName(storage)) at URL \"\(fileURL)\""
|
||||
"Attempted to migrate an already added \(cs_typeName(storage)) at URL \"\(fileURL)\""
|
||||
)
|
||||
|
||||
let metadata = try NSPersistentStoreCoordinator.metadataForPersistentStoreOfType(
|
||||
@@ -464,7 +464,7 @@ public extension DataStack {
|
||||
let metadataError = CoreStoreError(error)
|
||||
CoreStore.log(
|
||||
metadataError,
|
||||
"Failed to load \(typeName(storage)) metadata from URL \"\(fileURL)\"."
|
||||
"Failed to load \(cs_typeName(storage)) metadata from URL \"\(fileURL)\"."
|
||||
)
|
||||
throw metadataError
|
||||
}
|
||||
@@ -487,7 +487,7 @@ public extension DataStack {
|
||||
|
||||
CoreStore.assert(
|
||||
self.persistentStoreForStorage(storage) == nil,
|
||||
"Attempted to query required migrations for an already added \(typeName(storage)) at URL \"\(fileURL)\""
|
||||
"Attempted to query required migrations for an already added \(cs_typeName(storage)) at URL \"\(fileURL)\""
|
||||
)
|
||||
do {
|
||||
|
||||
@@ -506,7 +506,7 @@ public extension DataStack {
|
||||
)
|
||||
CoreStore.log(
|
||||
error,
|
||||
"Failed to find migration steps from the \(typeName(storage)) at URL \"\(fileURL)\" to version model \"\(self.modelVersion)\"."
|
||||
"Failed to find migration steps from the \(cs_typeName(storage)) at URL \"\(fileURL)\" to version model \"\(self.modelVersion)\"."
|
||||
)
|
||||
throw error
|
||||
}
|
||||
@@ -516,7 +516,7 @@ public extension DataStack {
|
||||
let error = CoreStoreError.ProgressiveMigrationRequired(localStoreURL: fileURL)
|
||||
CoreStore.log(
|
||||
error,
|
||||
"Failed to find migration mapping from the \(typeName(storage)) at URL \"\(fileURL)\" to version model \"\(self.modelVersion)\" without requiring progessive migrations."
|
||||
"Failed to find migration mapping from the \(cs_typeName(storage)) at URL \"\(fileURL)\" to version model \"\(self.modelVersion)\" without requiring progessive migrations."
|
||||
)
|
||||
throw error
|
||||
}
|
||||
@@ -533,7 +533,7 @@ public extension DataStack {
|
||||
let metadataError = CoreStoreError(error)
|
||||
CoreStore.log(
|
||||
metadataError,
|
||||
"Failed to load \(typeName(storage)) metadata from URL \"\(fileURL)\"."
|
||||
"Failed to load \(cs_typeName(storage)) metadata from URL \"\(fileURL)\"."
|
||||
)
|
||||
throw metadataError
|
||||
}
|
||||
@@ -554,7 +554,7 @@ public extension DataStack {
|
||||
)
|
||||
CoreStore.log(
|
||||
error,
|
||||
"Failed to find migration steps from \(typeName(storage)) at URL \"\(storage.fileURL)\" to version model \"\(self.model)\"."
|
||||
"Failed to find migration steps from \(cs_typeName(storage)) at URL \"\(storage.fileURL)\" to version model \"\(self.model)\"."
|
||||
)
|
||||
|
||||
GCDQueue.Main.async {
|
||||
@@ -579,7 +579,7 @@ public extension DataStack {
|
||||
let error = CoreStoreError.ProgressiveMigrationRequired(localStoreURL: storage.fileURL)
|
||||
CoreStore.log(
|
||||
error,
|
||||
"Failed to find migration mapping from the \(typeName(storage)) at URL \"\(storage.fileURL)\" to version model \"\(self.modelVersion)\" without requiring progessive migrations."
|
||||
"Failed to find migration mapping from the \(cs_typeName(storage)) at URL \"\(storage.fileURL)\" to version model \"\(self.modelVersion)\" without requiring progessive migrations."
|
||||
)
|
||||
GCDQueue.Main.async {
|
||||
|
||||
@@ -611,7 +611,7 @@ public extension DataStack {
|
||||
return
|
||||
}
|
||||
|
||||
autoreleasepool {
|
||||
cs_autoreleasepool {
|
||||
|
||||
do {
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@ public struct MigrationChain: NilLiteralConvertible, StringLiteralConvertible, D
|
||||
*/
|
||||
public init<T: CollectionType where T.Generator.Element == String, T.Index: BidirectionalIndexType>(_ elements: T) {
|
||||
|
||||
CoreStore.assert(Set(elements).count == Array(elements).count, "\(typeName(MigrationChain))'s migration chain could not be created due to duplicate version strings.")
|
||||
CoreStore.assert(Set(elements).count == Array(elements).count, "\(cs_typeName(MigrationChain))'s migration chain could not be created due to duplicate version strings.")
|
||||
|
||||
var lastVersion: String?
|
||||
var versionTree = [String: String]()
|
||||
@@ -124,7 +124,7 @@ public struct MigrationChain: NilLiteralConvertible, StringLiteralConvertible, D
|
||||
return
|
||||
}
|
||||
|
||||
CoreStore.assert(false, "\(typeName(MigrationChain))'s migration chain could not be created due to ambiguous version paths.")
|
||||
CoreStore.assert(false, "\(cs_typeName(MigrationChain))'s migration chain could not be created due to ambiguous version paths.")
|
||||
|
||||
valid = false
|
||||
}
|
||||
@@ -142,7 +142,7 @@ public struct MigrationChain: NilLiteralConvertible, StringLiteralConvertible, D
|
||||
|
||||
if checklist.contains(nextVersion) {
|
||||
|
||||
CoreStore.assert(false, "\(typeName(MigrationChain))'s migration chain could not be created due to looping version paths.")
|
||||
CoreStore.assert(false, "\(cs_typeName(MigrationChain))'s migration chain could not be created due to looping version paths.")
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ public extension CSBaseDataTransaction {
|
||||
|
||||
CoreStore.assert(
|
||||
self.bridgeToSwift.isRunningInAllowedQueue(),
|
||||
"Attempted to fetch from a \(typeName(self)) outside its designated queue."
|
||||
"Attempted to fetch from a \(cs_typeName(self)) outside its designated queue."
|
||||
)
|
||||
return self.bridgeToSwift.context.fetchOne(from, fetchClauses)
|
||||
}
|
||||
@@ -128,7 +128,7 @@ public extension CSBaseDataTransaction {
|
||||
|
||||
CoreStore.assert(
|
||||
self.bridgeToSwift.isRunningInAllowedQueue(),
|
||||
"Attempted to fetch from a \(typeName(self)) outside its designated queue."
|
||||
"Attempted to fetch from a \(cs_typeName(self)) outside its designated queue."
|
||||
)
|
||||
return self.bridgeToSwift.context.fetchAll(from, fetchClauses)
|
||||
}
|
||||
@@ -146,7 +146,7 @@ public extension CSBaseDataTransaction {
|
||||
|
||||
CoreStore.assert(
|
||||
self.bridgeToSwift.isRunningInAllowedQueue(),
|
||||
"Attempted to fetch from a \(typeName(self)) outside its designated queue."
|
||||
"Attempted to fetch from a \(cs_typeName(self)) outside its designated queue."
|
||||
)
|
||||
return self.bridgeToSwift.context.fetchCount(from, fetchClauses)
|
||||
}
|
||||
@@ -164,7 +164,7 @@ public extension CSBaseDataTransaction {
|
||||
|
||||
CoreStore.assert(
|
||||
self.bridgeToSwift.isRunningInAllowedQueue(),
|
||||
"Attempted to fetch from a \(typeName(self)) outside its designated queue."
|
||||
"Attempted to fetch from a \(cs_typeName(self)) outside its designated queue."
|
||||
)
|
||||
return self.bridgeToSwift.context.fetchObjectID(from, fetchClauses)
|
||||
}
|
||||
@@ -185,7 +185,7 @@ public extension CSBaseDataTransaction {
|
||||
|
||||
CoreStore.assert(
|
||||
self.bridgeToSwift.isRunningInAllowedQueue(),
|
||||
"Attempted to query from a \(typeName(self)) outside its designated queue."
|
||||
"Attempted to query from a \(cs_typeName(self)) outside its designated queue."
|
||||
)
|
||||
return self.bridgeToSwift.context.queryValue(from, selectClause, queryClauses)
|
||||
}
|
||||
@@ -206,7 +206,7 @@ public extension CSBaseDataTransaction {
|
||||
|
||||
CoreStore.assert(
|
||||
self.bridgeToSwift.isRunningInAllowedQueue(),
|
||||
"Attempted to query from a \(typeName(self)) outside its designated queue."
|
||||
"Attempted to query from a \(cs_typeName(self)) outside its designated queue."
|
||||
)
|
||||
return self.bridgeToSwift.context.queryAttributes(from, selectClause, queryClauses)
|
||||
}
|
||||
|
||||
@@ -47,12 +47,10 @@ public extension CSCoreStore {
|
||||
|
||||
- parameter storage: the `CSInMemoryStore` instance
|
||||
- parameter completion: the closure to be executed on the main queue when the process completes, either due to success or failure. The closure's `CSSetupResult` argument indicates the result. This closure is NOT executed if an error is thrown, but will be executed with a failure `CSSetupResult` result if an error occurs asynchronously.
|
||||
- parameter error: the `NSError` pointer that indicates the reason in case of an failure
|
||||
- returns: an `NSProgress` instance if a migration has started. `nil` if no migrations are required or if `error` was set.
|
||||
*/
|
||||
public static func addInMemoryStorage(storage: CSInMemoryStore, completion: (CSSetupResult) -> Void, error: NSErrorPointer) -> NSProgress? {
|
||||
public static func addInMemoryStorage(storage: CSInMemoryStore, completion: (CSSetupResult) -> Void) {
|
||||
|
||||
return self.defaultStack.addInMemoryStorage(storage, completion: completion, error: error)
|
||||
self.defaultStack.addInMemoryStorage(storage, completion: completion)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -47,19 +47,14 @@ public extension CSDataStack {
|
||||
|
||||
- parameter storage: the `CSInMemoryStore` instance
|
||||
- parameter completion: the closure to be executed on the main queue when the process completes, either due to success or failure. The closure's `CSSetupResult` argument indicates the result. This closure is NOT executed if an error is thrown, but will be executed with a failure `CSSetupResult` result if an error occurs asynchronously.
|
||||
- parameter error: the `NSError` pointer that indicates the reason in case of an failure
|
||||
- returns: an `NSProgress` instance if a migration has started. `nil` if no migrations are required or if `error` was set.
|
||||
*/
|
||||
@objc
|
||||
public func addInMemoryStorage(storage: CSInMemoryStore, completion: (CSSetupResult) -> Void, error: NSErrorPointer) -> NSProgress? {
|
||||
public func addInMemoryStorage(storage: CSInMemoryStore, completion: (CSSetupResult) -> Void) {
|
||||
|
||||
return bridge(error) {
|
||||
|
||||
try self.bridgeToSwift.addStorage(
|
||||
storage.bridgeToSwift,
|
||||
completion: { completion($0.bridgeToObjectiveC) }
|
||||
)
|
||||
}
|
||||
self.bridgeToSwift.addStorage(
|
||||
storage.bridgeToSwift,
|
||||
completion: { completion($0.bridgeToObjectiveC) }
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -61,7 +61,7 @@ public extension CSDataStack {
|
||||
|
||||
CoreStore.assert(
|
||||
NSThread.isMainThread(),
|
||||
"Attempted to observe objects from \(typeName(self)) outside the main thread."
|
||||
"Attempted to observe objects from \(cs_typeName(self)) outside the main thread."
|
||||
)
|
||||
CoreStore.assert(
|
||||
fetchClauses.contains { $0 is CSOrderBy },
|
||||
@@ -93,7 +93,7 @@ public extension CSDataStack {
|
||||
|
||||
CoreStore.assert(
|
||||
NSThread.isMainThread(),
|
||||
"Attempted to observe objects from \(typeName(self)) outside the main thread."
|
||||
"Attempted to observe objects from \(cs_typeName(self)) outside the main thread."
|
||||
)
|
||||
CoreStore.assert(
|
||||
fetchClauses.contains { $0 is CSOrderBy },
|
||||
@@ -128,7 +128,7 @@ public extension CSDataStack {
|
||||
|
||||
CoreStore.assert(
|
||||
NSThread.isMainThread(),
|
||||
"Attempted to observe objects from \(typeName(self)) outside the main thread."
|
||||
"Attempted to observe objects from \(cs_typeName(self)) outside the main thread."
|
||||
)
|
||||
CoreStore.assert(
|
||||
fetchClauses.contains { $0 is CSOrderBy },
|
||||
@@ -160,7 +160,7 @@ public extension CSDataStack {
|
||||
|
||||
CoreStore.assert(
|
||||
NSThread.isMainThread(),
|
||||
"Attempted to observe objects from \(typeName(self)) outside the main thread."
|
||||
"Attempted to observe objects from \(cs_typeName(self)) outside the main thread."
|
||||
)
|
||||
CoreStore.assert(
|
||||
fetchClauses.contains { $0 is CSOrderBy },
|
||||
|
||||
@@ -110,7 +110,7 @@ public extension CSDataStack {
|
||||
|
||||
CoreStore.assert(
|
||||
NSThread.isMainThread(),
|
||||
"Attempted to fetch from a \(typeName(self)) outside the main thread."
|
||||
"Attempted to fetch from a \(cs_typeName(self)) outside the main thread."
|
||||
)
|
||||
return self.bridgeToSwift.mainContext.fetchOne(from, fetchClauses)
|
||||
}
|
||||
@@ -128,7 +128,7 @@ public extension CSDataStack {
|
||||
|
||||
CoreStore.assert(
|
||||
NSThread.isMainThread(),
|
||||
"Attempted to fetch from a \(typeName(self)) outside the main thread."
|
||||
"Attempted to fetch from a \(cs_typeName(self)) outside the main thread."
|
||||
)
|
||||
return self.bridgeToSwift.mainContext.fetchAll(from, fetchClauses)
|
||||
}
|
||||
@@ -146,7 +146,7 @@ public extension CSDataStack {
|
||||
|
||||
CoreStore.assert(
|
||||
NSThread.isMainThread(),
|
||||
"Attempted to fetch from a \(typeName(self)) outside the main thread."
|
||||
"Attempted to fetch from a \(cs_typeName(self)) outside the main thread."
|
||||
)
|
||||
return self.bridgeToSwift.mainContext.fetchCount(from, fetchClauses)
|
||||
}
|
||||
@@ -164,7 +164,7 @@ public extension CSDataStack {
|
||||
|
||||
CoreStore.assert(
|
||||
NSThread.isMainThread(),
|
||||
"Attempted to fetch from a \(typeName(self)) outside the main thread."
|
||||
"Attempted to fetch from a \(cs_typeName(self)) outside the main thread."
|
||||
)
|
||||
return self.bridgeToSwift.mainContext.fetchObjectID(from, fetchClauses)
|
||||
}
|
||||
@@ -182,7 +182,7 @@ public extension CSDataStack {
|
||||
|
||||
CoreStore.assert(
|
||||
NSThread.isMainThread(),
|
||||
"Attempted to fetch from a \(typeName(self)) outside the main thread."
|
||||
"Attempted to fetch from a \(cs_typeName(self)) outside the main thread."
|
||||
)
|
||||
return self.bridgeToSwift.mainContext.fetchObjectIDs(from, fetchClauses)
|
||||
}
|
||||
@@ -203,7 +203,7 @@ public extension CSDataStack {
|
||||
|
||||
CoreStore.assert(
|
||||
NSThread.isMainThread(),
|
||||
"Attempted to query from a \(typeName(self)) outside the main thread."
|
||||
"Attempted to query from a \(cs_typeName(self)) outside the main thread."
|
||||
)
|
||||
return self.bridgeToSwift.mainContext.queryValue(from, selectClause, queryClauses)
|
||||
}
|
||||
@@ -224,7 +224,7 @@ public extension CSDataStack {
|
||||
|
||||
CoreStore.assert(
|
||||
NSThread.isMainThread(),
|
||||
"Attempted to query from a \(typeName(self)) outside the main thread."
|
||||
"Attempted to query from a \(cs_typeName(self)) outside the main thread."
|
||||
)
|
||||
return self.bridgeToSwift.mainContext.queryAttributes(from, selectClause, queryClauses)
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ public extension DataStack {
|
||||
|
||||
CoreStore.assert(
|
||||
NSThread.isMainThread(),
|
||||
"Attempted to observe objects from \(typeName(self)) outside the main thread."
|
||||
"Attempted to observe objects from \(cs_typeName(self)) outside the main thread."
|
||||
)
|
||||
return ObjectMonitor(dataStack: self, object: object)
|
||||
}
|
||||
@@ -76,7 +76,7 @@ public extension DataStack {
|
||||
|
||||
CoreStore.assert(
|
||||
NSThread.isMainThread(),
|
||||
"Attempted to observe objects from \(typeName(self)) outside the main thread."
|
||||
"Attempted to observe objects from \(cs_typeName(self)) outside the main thread."
|
||||
)
|
||||
CoreStore.assert(
|
||||
fetchClauses.contains { $0 is OrderBy },
|
||||
@@ -116,7 +116,7 @@ public extension DataStack {
|
||||
|
||||
CoreStore.assert(
|
||||
NSThread.isMainThread(),
|
||||
"Attempted to observe objects from \(typeName(self)) outside the main thread."
|
||||
"Attempted to observe objects from \(cs_typeName(self)) outside the main thread."
|
||||
)
|
||||
CoreStore.assert(
|
||||
fetchClauses.contains { $0 is OrderBy },
|
||||
@@ -161,7 +161,7 @@ public extension DataStack {
|
||||
|
||||
CoreStore.assert(
|
||||
NSThread.isMainThread(),
|
||||
"Attempted to observe objects from \(typeName(self)) outside the main thread."
|
||||
"Attempted to observe objects from \(cs_typeName(self)) outside the main thread."
|
||||
)
|
||||
CoreStore.assert(
|
||||
fetchClauses.contains { $0 is OrderBy },
|
||||
@@ -204,7 +204,7 @@ public extension DataStack {
|
||||
|
||||
CoreStore.assert(
|
||||
NSThread.isMainThread(),
|
||||
"Attempted to observe objects from \(typeName(self)) outside the main thread."
|
||||
"Attempted to observe objects from \(cs_typeName(self)) outside the main thread."
|
||||
)
|
||||
CoreStore.assert(
|
||||
fetchClauses.contains { $0 is OrderBy },
|
||||
|
||||
@@ -119,7 +119,7 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
|
||||
|
||||
CoreStore.assert(
|
||||
!self.isPendingRefetch || NSThread.isMainThread(),
|
||||
"Attempted to access a \(typeName(self)) outside the main thread while a refetch is in progress."
|
||||
"Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress."
|
||||
)
|
||||
|
||||
guard let sections = self.fetchedResultsController.sections
|
||||
@@ -146,7 +146,7 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
|
||||
|
||||
CoreStore.assert(
|
||||
!self.isPendingRefetch || NSThread.isMainThread(),
|
||||
"Attempted to access a \(typeName(self)) outside the main thread while a refetch is in progress."
|
||||
"Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress."
|
||||
)
|
||||
|
||||
return self.fetchedResultsController.objectAtIndexPath(indexPath) as! T
|
||||
@@ -199,7 +199,7 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
|
||||
|
||||
CoreStore.assert(
|
||||
!self.isPendingRefetch || NSThread.isMainThread(),
|
||||
"Attempted to access a \(typeName(self)) outside the main thread while a refetch is in progress."
|
||||
"Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress."
|
||||
)
|
||||
|
||||
return (self.fetchedResultsController.fetchedObjects as? [T]) ?? []
|
||||
@@ -216,7 +216,7 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
|
||||
|
||||
CoreStore.assert(
|
||||
!self.isPendingRefetch || NSThread.isMainThread(),
|
||||
"Attempted to access a \(typeName(self)) outside the main thread while a refetch is in progress."
|
||||
"Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress."
|
||||
)
|
||||
|
||||
return (self.fetchedResultsController.sections?[section].objects as? [T]) ?? []
|
||||
@@ -233,7 +233,7 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
|
||||
|
||||
CoreStore.assert(
|
||||
!self.isPendingRefetch || NSThread.isMainThread(),
|
||||
"Attempted to access a \(typeName(self)) outside the main thread while a refetch is in progress."
|
||||
"Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress."
|
||||
)
|
||||
|
||||
return (self.fetchedResultsController.sections?[section].objects as? [T]) ?? []
|
||||
@@ -249,7 +249,7 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
|
||||
|
||||
CoreStore.assert(
|
||||
!self.isPendingRefetch || NSThread.isMainThread(),
|
||||
"Attempted to access a \(typeName(self)) outside the main thread while a refetch is in progress."
|
||||
"Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress."
|
||||
)
|
||||
|
||||
return self.fetchedResultsController.sections?.count ?? 0
|
||||
@@ -265,7 +265,7 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
|
||||
|
||||
CoreStore.assert(
|
||||
!self.isPendingRefetch || NSThread.isMainThread(),
|
||||
"Attempted to access a \(typeName(self)) outside the main thread while a refetch is in progress."
|
||||
"Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress."
|
||||
)
|
||||
|
||||
return self.fetchedResultsController.fetchedObjects?.count ?? 0
|
||||
@@ -306,7 +306,7 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
|
||||
|
||||
CoreStore.assert(
|
||||
!self.isPendingRefetch || NSThread.isMainThread(),
|
||||
"Attempted to access a \(typeName(self)) outside the main thread while a refetch is in progress."
|
||||
"Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress."
|
||||
)
|
||||
|
||||
return self.fetchedResultsController.sections![section]
|
||||
@@ -323,7 +323,7 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
|
||||
|
||||
CoreStore.assert(
|
||||
!self.isPendingRefetch || NSThread.isMainThread(),
|
||||
"Attempted to access a \(typeName(self)) outside the main thread while a refetch is in progress."
|
||||
"Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress."
|
||||
)
|
||||
|
||||
guard let sections = self.fetchedResultsController.sections
|
||||
@@ -345,7 +345,7 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
|
||||
|
||||
CoreStore.assert(
|
||||
!self.isPendingRefetch || NSThread.isMainThread(),
|
||||
"Attempted to access a \(typeName(self)) outside the main thread while a refetch is in progress."
|
||||
"Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress."
|
||||
)
|
||||
|
||||
return self.fetchedResultsController.sections ?? []
|
||||
@@ -363,7 +363,7 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
|
||||
|
||||
CoreStore.assert(
|
||||
!self.isPendingRefetch || NSThread.isMainThread(),
|
||||
"Attempted to access a \(typeName(self)) outside the main thread while a refetch is in progress."
|
||||
"Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress."
|
||||
)
|
||||
|
||||
return self.fetchedResultsController.sectionForSectionIndexTitle(title, atIndex: index)
|
||||
@@ -379,7 +379,7 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
|
||||
|
||||
CoreStore.assert(
|
||||
!self.isPendingRefetch || NSThread.isMainThread(),
|
||||
"Attempted to access a \(typeName(self)) outside the main thread while a refetch is in progress."
|
||||
"Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress."
|
||||
)
|
||||
|
||||
return self.fetchedResultsController.sectionIndexTitles
|
||||
@@ -396,7 +396,7 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
|
||||
|
||||
CoreStore.assert(
|
||||
!self.isPendingRefetch || NSThread.isMainThread(),
|
||||
"Attempted to access a \(typeName(self)) outside the main thread while a refetch is in progress."
|
||||
"Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress."
|
||||
)
|
||||
|
||||
return (self.fetchedResultsController.fetchedObjects as? [T] ?? []).indexOf(object)
|
||||
@@ -413,7 +413,7 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
|
||||
|
||||
CoreStore.assert(
|
||||
!self.isPendingRefetch || NSThread.isMainThread(),
|
||||
"Attempted to access a \(typeName(self)) outside the main thread while a refetch is in progress."
|
||||
"Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress."
|
||||
)
|
||||
|
||||
return self.fetchedResultsController.indexPathForObject(object)
|
||||
@@ -689,7 +689,7 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
|
||||
|
||||
internal func registerChangeNotification(notificationKey: UnsafePointer<Void>, name: String, toObserver observer: AnyObject, callback: (monitor: ListMonitor<T>) -> Void) {
|
||||
|
||||
setAssociatedRetainedObject(
|
||||
cs_setAssociatedRetainedObject(
|
||||
NotificationObserver(
|
||||
notificationName: name,
|
||||
object: self,
|
||||
@@ -709,7 +709,7 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
|
||||
|
||||
internal func registerObjectNotification(notificationKey: UnsafePointer<Void>, name: String, toObserver observer: AnyObject, callback: (monitor: ListMonitor<T>, object: T, indexPath: NSIndexPath?, newIndexPath: NSIndexPath?) -> Void) {
|
||||
|
||||
setAssociatedRetainedObject(
|
||||
cs_setAssociatedRetainedObject(
|
||||
NotificationObserver(
|
||||
notificationName: name,
|
||||
object: self,
|
||||
@@ -736,7 +736,7 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
|
||||
|
||||
internal func registerSectionNotification(notificationKey: UnsafePointer<Void>, name: String, toObserver observer: AnyObject, callback: (monitor: ListMonitor<T>, sectionInfo: NSFetchedResultsSectionInfo, sectionIndex: Int) -> Void) {
|
||||
|
||||
setAssociatedRetainedObject(
|
||||
cs_setAssociatedRetainedObject(
|
||||
NotificationObserver(
|
||||
notificationName: name,
|
||||
object: self,
|
||||
@@ -765,7 +765,7 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
|
||||
|
||||
CoreStore.assert(
|
||||
NSThread.isMainThread(),
|
||||
"Attempted to add an observer of type \(typeName(observer)) outside the main thread."
|
||||
"Attempted to add an observer of type \(cs_typeName(observer)) outside the main thread."
|
||||
)
|
||||
|
||||
self.registerChangeNotification(
|
||||
@@ -826,7 +826,7 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
|
||||
|
||||
CoreStore.assert(
|
||||
NSThread.isMainThread(),
|
||||
"Attempted to add an observer of type \(typeName(observer)) outside the main thread."
|
||||
"Attempted to add an observer of type \(cs_typeName(observer)) outside the main thread."
|
||||
)
|
||||
|
||||
self.registerObjectNotification(
|
||||
@@ -908,7 +908,7 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
|
||||
|
||||
CoreStore.assert(
|
||||
NSThread.isMainThread(),
|
||||
"Attempted to add an observer of type \(typeName(observer)) outside the main thread."
|
||||
"Attempted to add an observer of type \(cs_typeName(observer)) outside the main thread."
|
||||
)
|
||||
|
||||
self.registerSectionNotification(
|
||||
@@ -953,29 +953,29 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
|
||||
|
||||
CoreStore.assert(
|
||||
NSThread.isMainThread(),
|
||||
"Attempted to remove an observer of type \(typeName(observer)) outside the main thread."
|
||||
"Attempted to remove an observer of type \(cs_typeName(observer)) outside the main thread."
|
||||
)
|
||||
|
||||
let nilValue: AnyObject? = nil
|
||||
setAssociatedRetainedObject(nilValue, forKey: &self.willChangeListKey, inObject: observer)
|
||||
setAssociatedRetainedObject(nilValue, forKey: &self.didChangeListKey, inObject: observer)
|
||||
setAssociatedRetainedObject(nilValue, forKey: &self.willRefetchListKey, inObject: observer)
|
||||
setAssociatedRetainedObject(nilValue, forKey: &self.didRefetchListKey, inObject: observer)
|
||||
cs_setAssociatedRetainedObject(nilValue, forKey: &self.willChangeListKey, inObject: observer)
|
||||
cs_setAssociatedRetainedObject(nilValue, forKey: &self.didChangeListKey, inObject: observer)
|
||||
cs_setAssociatedRetainedObject(nilValue, forKey: &self.willRefetchListKey, inObject: observer)
|
||||
cs_setAssociatedRetainedObject(nilValue, forKey: &self.didRefetchListKey, inObject: observer)
|
||||
|
||||
setAssociatedRetainedObject(nilValue, forKey: &self.didInsertObjectKey, inObject: observer)
|
||||
setAssociatedRetainedObject(nilValue, forKey: &self.didDeleteObjectKey, inObject: observer)
|
||||
setAssociatedRetainedObject(nilValue, forKey: &self.didUpdateObjectKey, inObject: observer)
|
||||
setAssociatedRetainedObject(nilValue, forKey: &self.didMoveObjectKey, inObject: observer)
|
||||
cs_setAssociatedRetainedObject(nilValue, forKey: &self.didInsertObjectKey, inObject: observer)
|
||||
cs_setAssociatedRetainedObject(nilValue, forKey: &self.didDeleteObjectKey, inObject: observer)
|
||||
cs_setAssociatedRetainedObject(nilValue, forKey: &self.didUpdateObjectKey, inObject: observer)
|
||||
cs_setAssociatedRetainedObject(nilValue, forKey: &self.didMoveObjectKey, inObject: observer)
|
||||
|
||||
setAssociatedRetainedObject(nilValue, forKey: &self.didInsertSectionKey, inObject: observer)
|
||||
setAssociatedRetainedObject(nilValue, forKey: &self.didDeleteSectionKey, inObject: observer)
|
||||
cs_setAssociatedRetainedObject(nilValue, forKey: &self.didInsertSectionKey, inObject: observer)
|
||||
cs_setAssociatedRetainedObject(nilValue, forKey: &self.didDeleteSectionKey, inObject: observer)
|
||||
}
|
||||
|
||||
internal func refetch(applyFetchClauses: (fetchRequest: NSFetchRequest) -> Void) {
|
||||
|
||||
CoreStore.assert(
|
||||
NSThread.isMainThread(),
|
||||
"Attempted to refetch a \(typeName(self)) outside the main thread."
|
||||
"Attempted to refetch a \(cs_typeName(self)) outside the main thread."
|
||||
)
|
||||
|
||||
if !self.isPendingRefetch {
|
||||
|
||||
@@ -129,7 +129,7 @@ public final class ObjectMonitor<T: NSManagedObject> {
|
||||
|
||||
CoreStore.assert(
|
||||
NSThread.isMainThread(),
|
||||
"Attempted to add an observer of type \(typeName(observer)) outside the main thread."
|
||||
"Attempted to add an observer of type \(cs_typeName(observer)) outside the main thread."
|
||||
)
|
||||
self.registerChangeNotification(
|
||||
&self.willChangeObjectKey,
|
||||
@@ -195,13 +195,13 @@ public final class ObjectMonitor<T: NSManagedObject> {
|
||||
|
||||
CoreStore.assert(
|
||||
NSThread.isMainThread(),
|
||||
"Attempted to remove an observer of type \(typeName(observer)) outside the main thread."
|
||||
"Attempted to remove an observer of type \(cs_typeName(observer)) outside the main thread."
|
||||
)
|
||||
|
||||
let nilValue: AnyObject? = nil
|
||||
setAssociatedRetainedObject(nilValue, forKey: &self.willChangeObjectKey, inObject: observer)
|
||||
setAssociatedRetainedObject(nilValue, forKey: &self.didDeleteObjectKey, inObject: observer)
|
||||
setAssociatedRetainedObject(nilValue, forKey: &self.didUpdateObjectKey, inObject: observer)
|
||||
cs_setAssociatedRetainedObject(nilValue, forKey: &self.willChangeObjectKey, inObject: observer)
|
||||
cs_setAssociatedRetainedObject(nilValue, forKey: &self.didDeleteObjectKey, inObject: observer)
|
||||
cs_setAssociatedRetainedObject(nilValue, forKey: &self.didUpdateObjectKey, inObject: observer)
|
||||
}
|
||||
|
||||
internal func upcast() -> ObjectMonitor<NSManagedObject> {
|
||||
@@ -256,7 +256,7 @@ public final class ObjectMonitor<T: NSManagedObject> {
|
||||
|
||||
private func registerChangeNotification(notificationKey: UnsafePointer<Void>, name: String, toObserver observer: AnyObject, callback: (monitor: ObjectMonitor<T>) -> Void) {
|
||||
|
||||
setAssociatedRetainedObject(
|
||||
cs_setAssociatedRetainedObject(
|
||||
NotificationObserver(
|
||||
notificationName: name,
|
||||
object: self,
|
||||
@@ -276,7 +276,7 @@ public final class ObjectMonitor<T: NSManagedObject> {
|
||||
|
||||
private func registerObjectNotification(notificationKey: UnsafePointer<Void>, name: String, toObserver observer: AnyObject, callback: (monitor: ObjectMonitor<T>, object: T) -> Void) {
|
||||
|
||||
setAssociatedRetainedObject(
|
||||
cs_setAssociatedRetainedObject(
|
||||
NotificationObserver(
|
||||
notificationName: name,
|
||||
object: self,
|
||||
|
||||
@@ -64,7 +64,7 @@ public final class DataStack {
|
||||
|
||||
CoreStore.assert(
|
||||
migrationChain.valid,
|
||||
"Invalid migration chain passed to the \(typeName(DataStack)). Check that the model versions' order is correct and that no repetitions or ambiguities exist."
|
||||
"Invalid migration chain passed to the \(cs_typeName(DataStack)). Check that the model versions' order is correct and that no repetitions or ambiguities exist."
|
||||
)
|
||||
|
||||
self.coordinator = NSPersistentStoreCoordinator(managedObjectModel: model)
|
||||
@@ -174,7 +174,7 @@ public final class DataStack {
|
||||
let storeError = CoreStoreError(error)
|
||||
CoreStore.log(
|
||||
storeError,
|
||||
"Failed to add \(typeName(storage)) to the stack."
|
||||
"Failed to add \(cs_typeName(storage)) to the stack."
|
||||
)
|
||||
throw storeError
|
||||
}
|
||||
@@ -212,7 +212,7 @@ public final class DataStack {
|
||||
let fileURL = storage.fileURL
|
||||
CoreStore.assert(
|
||||
fileURL.fileURL,
|
||||
"The specified store URL for the \"\(typeName(storage))\" is invalid: \"\(fileURL)\""
|
||||
"The specified store URL for the \"\(cs_typeName(storage))\" is invalid: \"\(fileURL)\""
|
||||
)
|
||||
|
||||
if let _ = self.persistentStoreForStorage(storage) {
|
||||
@@ -231,7 +231,7 @@ public final class DataStack {
|
||||
let error = CoreStoreError.DifferentStorageExistsAtURL(existingPersistentStoreURL: fileURL)
|
||||
CoreStore.log(
|
||||
error,
|
||||
"Failed to add \(typeName(storage)) at \"\(fileURL)\" because a different \(typeName(NSPersistentStore)) at that URL already exists."
|
||||
"Failed to add \(cs_typeName(storage)) at \"\(fileURL)\" because a different \(cs_typeName(NSPersistentStore)) at that URL already exists."
|
||||
)
|
||||
throw error
|
||||
}
|
||||
@@ -278,7 +278,7 @@ public final class DataStack {
|
||||
let storeError = CoreStoreError(error)
|
||||
CoreStore.log(
|
||||
storeError,
|
||||
"Failed to add \(typeName(storage)) to the stack."
|
||||
"Failed to add \(cs_typeName(storage)) to the stack."
|
||||
)
|
||||
throw storeError
|
||||
}
|
||||
@@ -325,7 +325,7 @@ public final class DataStack {
|
||||
let error = CoreStoreError.DifferentStorageExistsAtURL(existingPersistentStoreURL: cacheFileURL)
|
||||
CoreStore.log(
|
||||
error,
|
||||
"Failed to add \(typeName(storage)) at \"\(cacheFileURL)\" because a different \(typeName(NSPersistentStore)) at that URL already exists."
|
||||
"Failed to add \(cs_typeName(storage)) at \"\(cacheFileURL)\" because a different \(cs_typeName(NSPersistentStore)) at that URL already exists."
|
||||
)
|
||||
throw error
|
||||
}
|
||||
@@ -372,7 +372,7 @@ public final class DataStack {
|
||||
let storeError = CoreStoreError(error)
|
||||
CoreStore.log(
|
||||
storeError,
|
||||
"Failed to add \(typeName(storage)) to the stack."
|
||||
"Failed to add \(cs_typeName(storage)) to the stack."
|
||||
)
|
||||
throw storeError
|
||||
}
|
||||
@@ -489,7 +489,7 @@ public final class DataStack {
|
||||
let managedObjectClassName = entityDescription.managedObjectClassName
|
||||
CoreStore.assert(
|
||||
NSClassFromString(managedObjectClassName) != nil,
|
||||
"The class \(typeName(managedObjectClassName)) for the entity \(typeName(entityDescription.name)) does not exist. Check if the subclass type and module name are properly configured."
|
||||
"The class \(cs_typeName(managedObjectClassName)) for the entity \(cs_typeName(entityDescription.name)) does not exist. Check if the subclass type and module name are properly configured."
|
||||
)
|
||||
|
||||
if self.entityConfigurationsMapping[managedObjectClassName] == nil {
|
||||
|
||||
@@ -108,7 +108,7 @@ public class ICloudStore: CloudStorage {
|
||||
|
||||
CoreStore.assert(
|
||||
NSThread.isMainThread(),
|
||||
"Attempted to add an observer of type \(typeName(observer)) outside the main thread."
|
||||
"Attempted to add an observer of type \(cs_typeName(observer)) outside the main thread."
|
||||
)
|
||||
|
||||
self.removeObserver(observer)
|
||||
@@ -196,45 +196,45 @@ public class ICloudStore: CloudStorage {
|
||||
|
||||
CoreStore.assert(
|
||||
NSThread.isMainThread(),
|
||||
"Attempted to remove an observer of type \(typeName(observer)) outside the main thread."
|
||||
"Attempted to remove an observer of type \(cs_typeName(observer)) outside the main thread."
|
||||
)
|
||||
let nilValue: AnyObject? = nil
|
||||
setAssociatedRetainedObject(
|
||||
cs_setAssociatedRetainedObject(
|
||||
nilValue,
|
||||
forKey: &self.willFinishInitialImportKey,
|
||||
inObject: observer
|
||||
)
|
||||
setAssociatedRetainedObject(
|
||||
cs_setAssociatedRetainedObject(
|
||||
nilValue,
|
||||
forKey: &self.didFinishInitialImportKey,
|
||||
inObject: observer
|
||||
)
|
||||
setAssociatedRetainedObject(
|
||||
cs_setAssociatedRetainedObject(
|
||||
nilValue,
|
||||
forKey: &self.willAddAccountKey,
|
||||
inObject: observer
|
||||
)
|
||||
setAssociatedRetainedObject(
|
||||
cs_setAssociatedRetainedObject(
|
||||
nilValue,
|
||||
forKey: &self.didAddAccountKey,
|
||||
inObject: observer
|
||||
)
|
||||
setAssociatedRetainedObject(
|
||||
cs_setAssociatedRetainedObject(
|
||||
nilValue,
|
||||
forKey: &self.willRemoveAccountKey,
|
||||
inObject: observer
|
||||
)
|
||||
setAssociatedRetainedObject(
|
||||
cs_setAssociatedRetainedObject(
|
||||
nilValue,
|
||||
forKey: &self.didRemoveAccountKey,
|
||||
inObject: observer
|
||||
)
|
||||
setAssociatedRetainedObject(
|
||||
cs_setAssociatedRetainedObject(
|
||||
nilValue,
|
||||
forKey: &self.willRemoveContentKey,
|
||||
inObject: observer
|
||||
)
|
||||
setAssociatedRetainedObject(
|
||||
cs_setAssociatedRetainedObject(
|
||||
nilValue,
|
||||
forKey: &self.didRemoveContentKey,
|
||||
inObject: observer
|
||||
@@ -272,7 +272,7 @@ public class ICloudStore: CloudStorage {
|
||||
self.dataStack = dataStack
|
||||
let coordinator = dataStack.coordinator
|
||||
|
||||
setAssociatedRetainedObject(
|
||||
cs_setAssociatedRetainedObject(
|
||||
NotificationObserver(
|
||||
notificationName: NSPersistentStoreCoordinatorStoresWillChangeNotification,
|
||||
object: coordinator,
|
||||
@@ -314,7 +314,7 @@ public class ICloudStore: CloudStorage {
|
||||
forKey: &Static.persistentStoreCoordinatorWillChangeStores,
|
||||
inObject: self
|
||||
)
|
||||
setAssociatedRetainedObject(
|
||||
cs_setAssociatedRetainedObject(
|
||||
NotificationObserver(
|
||||
notificationName: NSPersistentStoreCoordinatorStoresDidChangeNotification,
|
||||
object: coordinator,
|
||||
@@ -365,12 +365,12 @@ public class ICloudStore: CloudStorage {
|
||||
|
||||
let coordinator = dataStack.coordinator
|
||||
let nilValue: AnyObject? = nil
|
||||
setAssociatedRetainedObject(
|
||||
cs_setAssociatedRetainedObject(
|
||||
nilValue,
|
||||
forKey: &Static.persistentStoreCoordinatorWillChangeStores,
|
||||
inObject: coordinator
|
||||
)
|
||||
setAssociatedRetainedObject(
|
||||
cs_setAssociatedRetainedObject(
|
||||
nilValue,
|
||||
forKey: &Static.persistentStoreCoordinatorDidChangeStores,
|
||||
inObject: coordinator
|
||||
@@ -423,7 +423,7 @@ public class ICloudStore: CloudStorage {
|
||||
// TODO: check if attached to persistent store
|
||||
|
||||
let cacheFileURL = self.cacheFileURL
|
||||
try autoreleasepool {
|
||||
try cs_autoreleasepool {
|
||||
|
||||
let journalUpdatingCoordinator = NSPersistentStoreCoordinator(managedObjectModel: soureModel)
|
||||
let options = [
|
||||
@@ -467,7 +467,7 @@ public class ICloudStore: CloudStorage {
|
||||
|
||||
private func registerNotification<T: ICloudStoreObserver>(notificationKey: UnsafePointer<Void>, name: String, toObserver observer: T, callback: (observer: T, storage: ICloudStore, dataStack: DataStack) -> Void) {
|
||||
|
||||
setAssociatedRetainedObject(
|
||||
cs_setAssociatedRetainedObject(
|
||||
NotificationObserver(
|
||||
notificationName: name,
|
||||
object: self,
|
||||
|
||||
@@ -105,14 +105,18 @@ public protocol ICloudStoreObserver: class {
|
||||
public extension ICloudStoreObserver {
|
||||
|
||||
public func iCloudStoreWillFinishUbiquitousStoreInitialImport(storage storage: ICloudStore, dataStack: DataStack) {}
|
||||
|
||||
public func iCloudStoreDidFinishUbiquitousStoreInitialImport(storage storage: ICloudStore, dataStack: DataStack) {}
|
||||
|
||||
public func iCloudStoreWillAddAccount(storage storage: ICloudStore, dataStack: DataStack) {}
|
||||
|
||||
public func iCloudStoreDidAddAccount(storage storage: ICloudStore, dataStack: DataStack) {}
|
||||
|
||||
public func iCloudStoreWillRemoveAccount(storage storage: ICloudStore, dataStack: DataStack) {}
|
||||
|
||||
public func iCloudStoreDidRemoveAccount(storage storage: ICloudStore, dataStack: DataStack) {}
|
||||
|
||||
public func iCloudStoreWillRemoveContent(storage storage: ICloudStore, dataStack: DataStack) {}
|
||||
|
||||
public func iCloudStoreDidRemoveContent(storage storage: ICloudStore, dataStack: DataStack) {}
|
||||
}
|
||||
|
||||
@@ -169,7 +169,7 @@ public final class LegacySQLiteStore: LocalStorage, DefaultInitializableStore {
|
||||
// TODO: check if attached to persistent store
|
||||
|
||||
let fileURL = self.fileURL
|
||||
try autoreleasepool {
|
||||
try cs_autoreleasepool {
|
||||
|
||||
let journalUpdatingCoordinator = NSPersistentStoreCoordinator(managedObjectModel: soureModel)
|
||||
let store = try journalUpdatingCoordinator.addPersistentStoreWithType(
|
||||
|
||||
@@ -167,7 +167,7 @@ public final class SQLiteStore: LocalStorage, DefaultInitializableStore {
|
||||
// TODO: check if attached to persistent store
|
||||
|
||||
let fileURL = self.fileURL
|
||||
try autoreleasepool {
|
||||
try cs_autoreleasepool {
|
||||
|
||||
let journalUpdatingCoordinator = NSPersistentStoreCoordinator(managedObjectModel: soureModel)
|
||||
let store = try journalUpdatingCoordinator.addPersistentStoreWithType(
|
||||
|
||||
@@ -46,11 +46,11 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
|
||||
|
||||
CoreStore.assert(
|
||||
self.transactionQueue.isCurrentExecutionContext(),
|
||||
"Attempted to commit a \(typeName(self)) outside its designated queue."
|
||||
"Attempted to commit a \(cs_typeName(self)) outside its designated queue."
|
||||
)
|
||||
CoreStore.assert(
|
||||
!self.isCommitted,
|
||||
"Attempted to commit a \(typeName(self)) more than once."
|
||||
"Attempted to commit a \(cs_typeName(self)) more than once."
|
||||
)
|
||||
|
||||
self.isCommitted = true
|
||||
@@ -75,11 +75,11 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
|
||||
|
||||
CoreStore.assert(
|
||||
self.transactionQueue.isCurrentExecutionContext(),
|
||||
"Attempted to begin a child transaction from a \(typeName(self)) outside its designated queue."
|
||||
"Attempted to begin a child transaction from a \(cs_typeName(self)) outside its designated queue."
|
||||
)
|
||||
CoreStore.assert(
|
||||
!self.isCommitted,
|
||||
"Attempted to begin a child transaction from an already committed \(typeName(self))."
|
||||
"Attempted to begin a child transaction from an already committed \(cs_typeName(self))."
|
||||
)
|
||||
|
||||
return SynchronousDataTransaction(
|
||||
@@ -101,7 +101,7 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
|
||||
|
||||
CoreStore.assert(
|
||||
!self.isCommitted,
|
||||
"Attempted to create an entity of type \(typeName(T)) from an already committed \(typeName(self))."
|
||||
"Attempted to create an entity of type \(cs_typeName(T)) from an already committed \(cs_typeName(self))."
|
||||
)
|
||||
|
||||
return super.create(into)
|
||||
@@ -118,7 +118,7 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
|
||||
|
||||
CoreStore.assert(
|
||||
!self.isCommitted,
|
||||
"Attempted to update an entity of type \(typeName(object)) from an already committed \(typeName(self))."
|
||||
"Attempted to update an entity of type \(cs_typeName(object)) from an already committed \(cs_typeName(self))."
|
||||
)
|
||||
|
||||
return super.edit(object)
|
||||
@@ -136,7 +136,7 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
|
||||
|
||||
CoreStore.assert(
|
||||
!self.isCommitted,
|
||||
"Attempted to update an entity of type \(typeName(T)) from an already committed \(typeName(self))."
|
||||
"Attempted to update an entity of type \(cs_typeName(T)) from an already committed \(cs_typeName(self))."
|
||||
)
|
||||
|
||||
return super.edit(into, objectID)
|
||||
@@ -151,7 +151,7 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
|
||||
|
||||
CoreStore.assert(
|
||||
!self.isCommitted,
|
||||
"Attempted to delete an entity of type \(typeName(object)) from an already committed \(typeName(self))."
|
||||
"Attempted to delete an entity of type \(cs_typeName(object)) from an already committed \(cs_typeName(self))."
|
||||
)
|
||||
|
||||
super.delete(object)
|
||||
@@ -168,7 +168,7 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
|
||||
|
||||
CoreStore.assert(
|
||||
!self.isCommitted,
|
||||
"Attempted to delete an entities from an already committed \(typeName(self))."
|
||||
"Attempted to delete an entities from an already committed \(cs_typeName(self))."
|
||||
)
|
||||
|
||||
super.delete(([object1, object2] + objects).flatMap { $0 })
|
||||
@@ -183,7 +183,7 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
|
||||
|
||||
CoreStore.assert(
|
||||
!self.isCommitted,
|
||||
"Attempted to delete an entities from an already committed \(typeName(self))."
|
||||
"Attempted to delete an entities from an already committed \(cs_typeName(self))."
|
||||
)
|
||||
|
||||
super.delete(objects)
|
||||
@@ -208,7 +208,7 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
|
||||
|
||||
CoreStore.log(
|
||||
.Warning,
|
||||
message: "The closure for the \(typeName(self)) completed without being committed. All changes made within the transaction were discarded."
|
||||
message: "The closure for the \(cs_typeName(self)) completed without being committed. All changes made within the transaction were discarded."
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -224,7 +224,7 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
|
||||
|
||||
CoreStore.log(
|
||||
.Warning,
|
||||
message: "The closure for the \(typeName(self)) completed without being committed. All changes made within the transaction were discarded."
|
||||
message: "The closure for the \(cs_typeName(self)) completed without being committed. All changes made within the transaction were discarded."
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -244,11 +244,11 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
|
||||
|
||||
CoreStore.assert(
|
||||
!self.isCommitted,
|
||||
"Attempted to rollback an already committed \(typeName(self))."
|
||||
"Attempted to rollback an already committed \(cs_typeName(self))."
|
||||
)
|
||||
CoreStore.assert(
|
||||
self.transactionQueue.isCurrentExecutionContext(),
|
||||
"Attempted to rollback a \(typeName(self)) outside its designated queue."
|
||||
"Attempted to rollback a \(cs_typeName(self)) outside its designated queue."
|
||||
)
|
||||
|
||||
self.context.reset()
|
||||
|
||||
@@ -57,7 +57,7 @@ public /*abstract*/ class BaseDataTransaction {
|
||||
|
||||
CoreStore.assert(
|
||||
self.isRunningInAllowedQueue(),
|
||||
"Attempted to create an entity of type \(typeName(T)) outside its designated queue."
|
||||
"Attempted to create an entity of type \(cs_typeName(T)) outside its designated queue."
|
||||
)
|
||||
|
||||
let context = self.context
|
||||
@@ -72,10 +72,10 @@ public /*abstract*/ class BaseDataTransaction {
|
||||
return object
|
||||
|
||||
case (nil, true):
|
||||
fatalError("Attempted to create an entity of type \(typeName(entityClass)) with ambiguous destination persistent store, but the configuration name was not specified.")
|
||||
fatalError("Attempted to create an entity of type \(cs_typeName(entityClass)) with ambiguous destination persistent store, but the configuration name was not specified.")
|
||||
|
||||
default:
|
||||
fatalError("Attempted to create an entity of type \(typeName(entityClass)), but a destination persistent store containing the entity type could not be found.")
|
||||
fatalError("Attempted to create an entity of type \(cs_typeName(entityClass)), but a destination persistent store containing the entity type could not be found.")
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -90,11 +90,11 @@ public /*abstract*/ class BaseDataTransaction {
|
||||
default:
|
||||
if let configuration = into.configuration {
|
||||
|
||||
fatalError("Attempted to create an entity of type \(typeName(entityClass)) into the configuration \"\(configuration)\", which it doesn't belong to.")
|
||||
fatalError("Attempted to create an entity of type \(cs_typeName(entityClass)) into the configuration \"\(configuration)\", which it doesn't belong to.")
|
||||
}
|
||||
else {
|
||||
|
||||
fatalError("Attempted to create an entity of type \(typeName(entityClass)) into the default configuration, which it doesn't belong to.")
|
||||
fatalError("Attempted to create an entity of type \(cs_typeName(entityClass)) into the default configuration, which it doesn't belong to.")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -111,7 +111,7 @@ public /*abstract*/ class BaseDataTransaction {
|
||||
|
||||
CoreStore.assert(
|
||||
self.isRunningInAllowedQueue(),
|
||||
"Attempted to update an entity of type \(typeName(object)) outside its designated queue."
|
||||
"Attempted to update an entity of type \(cs_typeName(object)) outside its designated queue."
|
||||
)
|
||||
guard let object = object else {
|
||||
|
||||
@@ -132,12 +132,12 @@ public /*abstract*/ class BaseDataTransaction {
|
||||
|
||||
CoreStore.assert(
|
||||
self.isRunningInAllowedQueue(),
|
||||
"Attempted to update an entity of type \(typeName(T)) outside its designated queue."
|
||||
"Attempted to update an entity of type \(cs_typeName(T)) outside its designated queue."
|
||||
)
|
||||
CoreStore.assert(
|
||||
into.inferStoreIfPossible
|
||||
|| (into.configuration ?? Into.defaultConfigurationName) == objectID.persistentStore?.configurationName,
|
||||
"Attempted to update an entity of type \(typeName(T)) but the specified persistent store do not match the `NSManagedObjectID`."
|
||||
"Attempted to update an entity of type \(cs_typeName(T)) but the specified persistent store do not match the `NSManagedObjectID`."
|
||||
)
|
||||
return self.fetchExisting(objectID) as? T
|
||||
}
|
||||
@@ -214,11 +214,11 @@ public /*abstract*/ class BaseDataTransaction {
|
||||
|
||||
CoreStore.assert(
|
||||
self.transactionQueue.isCurrentExecutionContext(),
|
||||
"Attempted to access inserted objects from a \(typeName(self)) outside its designated queue."
|
||||
"Attempted to access inserted objects from a \(cs_typeName(self)) outside its designated queue."
|
||||
)
|
||||
CoreStore.assert(
|
||||
!self.isCommitted,
|
||||
"Attempted to access inserted objects from an already committed \(typeName(self))."
|
||||
"Attempted to access inserted objects from an already committed \(cs_typeName(self))."
|
||||
)
|
||||
|
||||
return self.context.insertedObjects
|
||||
@@ -235,11 +235,11 @@ public /*abstract*/ class BaseDataTransaction {
|
||||
|
||||
CoreStore.assert(
|
||||
self.transactionQueue.isCurrentExecutionContext(),
|
||||
"Attempted to access inserted objects from a \(typeName(self)) outside its designated queue."
|
||||
"Attempted to access inserted objects from a \(cs_typeName(self)) outside its designated queue."
|
||||
)
|
||||
CoreStore.assert(
|
||||
!self.isCommitted,
|
||||
"Attempted to access inserted objects from an already committed \(typeName(self))."
|
||||
"Attempted to access inserted objects from an already committed \(cs_typeName(self))."
|
||||
)
|
||||
|
||||
return Set(self.context.insertedObjects.flatMap { $0 as? T })
|
||||
@@ -255,11 +255,11 @@ public /*abstract*/ class BaseDataTransaction {
|
||||
|
||||
CoreStore.assert(
|
||||
self.transactionQueue.isCurrentExecutionContext(),
|
||||
"Attempted to access inserted object IDs from a \(typeName(self)) outside its designated queue."
|
||||
"Attempted to access inserted object IDs from a \(cs_typeName(self)) outside its designated queue."
|
||||
)
|
||||
CoreStore.assert(
|
||||
!self.isCommitted,
|
||||
"Attempted to access inserted objects IDs from an already committed \(typeName(self))."
|
||||
"Attempted to access inserted objects IDs from an already committed \(cs_typeName(self))."
|
||||
)
|
||||
|
||||
return Set(self.context.insertedObjects.map { $0.objectID })
|
||||
@@ -276,11 +276,11 @@ public /*abstract*/ class BaseDataTransaction {
|
||||
|
||||
CoreStore.assert(
|
||||
self.transactionQueue.isCurrentExecutionContext(),
|
||||
"Attempted to access inserted object IDs from a \(typeName(self)) outside its designated queue."
|
||||
"Attempted to access inserted object IDs from a \(cs_typeName(self)) outside its designated queue."
|
||||
)
|
||||
CoreStore.assert(
|
||||
!self.isCommitted,
|
||||
"Attempted to access inserted objects IDs from an already committed \(typeName(self))."
|
||||
"Attempted to access inserted objects IDs from an already committed \(cs_typeName(self))."
|
||||
)
|
||||
|
||||
return Set(self.context.insertedObjects.filter { $0.isKindOfClass(entity) }.map { $0.objectID })
|
||||
@@ -296,11 +296,11 @@ public /*abstract*/ class BaseDataTransaction {
|
||||
|
||||
CoreStore.assert(
|
||||
self.transactionQueue.isCurrentExecutionContext(),
|
||||
"Attempted to access updated objects from a \(typeName(self)) outside its designated queue."
|
||||
"Attempted to access updated objects from a \(cs_typeName(self)) outside its designated queue."
|
||||
)
|
||||
CoreStore.assert(
|
||||
!self.isCommitted,
|
||||
"Attempted to access updated objects from an already committed \(typeName(self))."
|
||||
"Attempted to access updated objects from an already committed \(cs_typeName(self))."
|
||||
)
|
||||
|
||||
return self.context.updatedObjects
|
||||
@@ -317,11 +317,11 @@ public /*abstract*/ class BaseDataTransaction {
|
||||
|
||||
CoreStore.assert(
|
||||
self.transactionQueue.isCurrentExecutionContext(),
|
||||
"Attempted to access updated objects from a \(typeName(self)) outside its designated queue."
|
||||
"Attempted to access updated objects from a \(cs_typeName(self)) outside its designated queue."
|
||||
)
|
||||
CoreStore.assert(
|
||||
!self.isCommitted,
|
||||
"Attempted to access updated objects from an already committed \(typeName(self))."
|
||||
"Attempted to access updated objects from an already committed \(cs_typeName(self))."
|
||||
)
|
||||
|
||||
return Set(self.context.updatedObjects.filter { $0.isKindOfClass(entity) }.map { $0 as! T })
|
||||
@@ -337,11 +337,11 @@ public /*abstract*/ class BaseDataTransaction {
|
||||
|
||||
CoreStore.assert(
|
||||
self.transactionQueue.isCurrentExecutionContext(),
|
||||
"Attempted to access updated object IDs from a \(typeName(self)) outside its designated queue."
|
||||
"Attempted to access updated object IDs from a \(cs_typeName(self)) outside its designated queue."
|
||||
)
|
||||
CoreStore.assert(
|
||||
!self.isCommitted,
|
||||
"Attempted to access updated object IDs from an already committed \(typeName(self))."
|
||||
"Attempted to access updated object IDs from an already committed \(cs_typeName(self))."
|
||||
)
|
||||
|
||||
return Set(self.context.updatedObjects.map { $0.objectID })
|
||||
@@ -358,11 +358,11 @@ public /*abstract*/ class BaseDataTransaction {
|
||||
|
||||
CoreStore.assert(
|
||||
self.transactionQueue.isCurrentExecutionContext(),
|
||||
"Attempted to access updated object IDs from a \(typeName(self)) outside its designated queue."
|
||||
"Attempted to access updated object IDs from a \(cs_typeName(self)) outside its designated queue."
|
||||
)
|
||||
CoreStore.assert(
|
||||
!self.isCommitted,
|
||||
"Attempted to access updated object IDs from an already committed \(typeName(self))."
|
||||
"Attempted to access updated object IDs from an already committed \(cs_typeName(self))."
|
||||
)
|
||||
|
||||
return Set(self.context.updatedObjects.filter { $0.isKindOfClass(entity) }.map { $0.objectID })
|
||||
@@ -378,11 +378,11 @@ public /*abstract*/ class BaseDataTransaction {
|
||||
|
||||
CoreStore.assert(
|
||||
self.transactionQueue.isCurrentExecutionContext(),
|
||||
"Attempted to access deleted objects from a \(typeName(self)) outside its designated queue."
|
||||
"Attempted to access deleted objects from a \(cs_typeName(self)) outside its designated queue."
|
||||
)
|
||||
CoreStore.assert(
|
||||
!self.isCommitted,
|
||||
"Attempted to access deleted objects from an already committed \(typeName(self))."
|
||||
"Attempted to access deleted objects from an already committed \(cs_typeName(self))."
|
||||
)
|
||||
|
||||
return self.context.deletedObjects
|
||||
@@ -399,11 +399,11 @@ public /*abstract*/ class BaseDataTransaction {
|
||||
|
||||
CoreStore.assert(
|
||||
self.transactionQueue.isCurrentExecutionContext(),
|
||||
"Attempted to access deleted objects from a \(typeName(self)) outside its designated queue."
|
||||
"Attempted to access deleted objects from a \(cs_typeName(self)) outside its designated queue."
|
||||
)
|
||||
CoreStore.assert(
|
||||
!self.isCommitted,
|
||||
"Attempted to access deleted objects from an already committed \(typeName(self))."
|
||||
"Attempted to access deleted objects from an already committed \(cs_typeName(self))."
|
||||
)
|
||||
|
||||
return Set(self.context.deletedObjects.filter { $0.isKindOfClass(entity) }.map { $0 as! T })
|
||||
@@ -420,11 +420,11 @@ public /*abstract*/ class BaseDataTransaction {
|
||||
|
||||
CoreStore.assert(
|
||||
self.transactionQueue.isCurrentExecutionContext(),
|
||||
"Attempted to access deleted object IDs from a \(typeName(self)) outside its designated queue."
|
||||
"Attempted to access deleted object IDs from a \(cs_typeName(self)) outside its designated queue."
|
||||
)
|
||||
CoreStore.assert(
|
||||
!self.isCommitted,
|
||||
"Attempted to access deleted object IDs from an already committed \(typeName(self))."
|
||||
"Attempted to access deleted object IDs from an already committed \(cs_typeName(self))."
|
||||
)
|
||||
|
||||
return Set(self.context.deletedObjects.map { $0.objectID })
|
||||
@@ -441,11 +441,11 @@ public /*abstract*/ class BaseDataTransaction {
|
||||
|
||||
CoreStore.assert(
|
||||
self.transactionQueue.isCurrentExecutionContext(),
|
||||
"Attempted to access deleted object IDs from a \(typeName(self)) outside its designated queue."
|
||||
"Attempted to access deleted object IDs from a \(cs_typeName(self)) outside its designated queue."
|
||||
)
|
||||
CoreStore.assert(
|
||||
!self.isCommitted,
|
||||
"Attempted to access deleted object IDs from an already committed \(typeName(self))."
|
||||
"Attempted to access deleted object IDs from an already committed \(cs_typeName(self))."
|
||||
)
|
||||
|
||||
return Set(self.context.deletedObjects.filter { $0.isKindOfClass(entity) }.map { $0.objectID })
|
||||
|
||||
@@ -46,11 +46,11 @@ public final class SynchronousDataTransaction: BaseDataTransaction {
|
||||
|
||||
CoreStore.assert(
|
||||
self.transactionQueue.isCurrentExecutionContext(),
|
||||
"Attempted to commit a \(typeName(self)) outside its designated queue."
|
||||
"Attempted to commit a \(cs_typeName(self)) outside its designated queue."
|
||||
)
|
||||
CoreStore.assert(
|
||||
!self.isCommitted,
|
||||
"Attempted to commit a \(typeName(self)) more than once."
|
||||
"Attempted to commit a \(cs_typeName(self)) more than once."
|
||||
)
|
||||
|
||||
self.isCommitted = true
|
||||
@@ -70,11 +70,11 @@ public final class SynchronousDataTransaction: BaseDataTransaction {
|
||||
|
||||
CoreStore.assert(
|
||||
self.transactionQueue.isCurrentExecutionContext(),
|
||||
"Attempted to begin a child transaction from a \(typeName(self)) outside its designated queue."
|
||||
"Attempted to begin a child transaction from a \(cs_typeName(self)) outside its designated queue."
|
||||
)
|
||||
CoreStore.assert(
|
||||
!self.isCommitted,
|
||||
"Attempted to begin a child transaction from an already committed \(typeName(self))."
|
||||
"Attempted to begin a child transaction from an already committed \(cs_typeName(self))."
|
||||
)
|
||||
|
||||
return SynchronousDataTransaction(
|
||||
@@ -96,7 +96,7 @@ public final class SynchronousDataTransaction: BaseDataTransaction {
|
||||
|
||||
CoreStore.assert(
|
||||
!self.isCommitted,
|
||||
"Attempted to create an entity of type \(typeName(T)) from an already committed \(typeName(self))."
|
||||
"Attempted to create an entity of type \(cs_typeName(T)) from an already committed \(cs_typeName(self))."
|
||||
)
|
||||
|
||||
return super.create(into)
|
||||
@@ -113,7 +113,7 @@ public final class SynchronousDataTransaction: BaseDataTransaction {
|
||||
|
||||
CoreStore.assert(
|
||||
!self.isCommitted,
|
||||
"Attempted to update an entity of type \(typeName(object)) from an already committed \(typeName(self))."
|
||||
"Attempted to update an entity of type \(cs_typeName(object)) from an already committed \(cs_typeName(self))."
|
||||
)
|
||||
|
||||
return super.edit(object)
|
||||
@@ -131,7 +131,7 @@ public final class SynchronousDataTransaction: BaseDataTransaction {
|
||||
|
||||
CoreStore.assert(
|
||||
!self.isCommitted,
|
||||
"Attempted to update an entity of type \(typeName(T)) from an already committed \(typeName(self))."
|
||||
"Attempted to update an entity of type \(cs_typeName(T)) from an already committed \(cs_typeName(self))."
|
||||
)
|
||||
|
||||
return super.edit(into, objectID)
|
||||
@@ -146,7 +146,7 @@ public final class SynchronousDataTransaction: BaseDataTransaction {
|
||||
|
||||
CoreStore.assert(
|
||||
!self.isCommitted,
|
||||
"Attempted to delete an entity of type \(typeName(object)) from an already committed \(typeName(self))."
|
||||
"Attempted to delete an entity of type \(cs_typeName(object)) from an already committed \(cs_typeName(self))."
|
||||
)
|
||||
|
||||
super.delete(object)
|
||||
@@ -163,7 +163,7 @@ public final class SynchronousDataTransaction: BaseDataTransaction {
|
||||
|
||||
CoreStore.assert(
|
||||
!self.isCommitted,
|
||||
"Attempted to delete an entities from an already committed \(typeName(self))."
|
||||
"Attempted to delete an entities from an already committed \(cs_typeName(self))."
|
||||
)
|
||||
|
||||
super.delete(([object1, object2] + objects).flatMap { $0 })
|
||||
@@ -178,7 +178,7 @@ public final class SynchronousDataTransaction: BaseDataTransaction {
|
||||
|
||||
CoreStore.assert(
|
||||
!self.isCommitted,
|
||||
"Attempted to delete an entities from an already committed \(typeName(self))."
|
||||
"Attempted to delete an entities from an already committed \(cs_typeName(self))."
|
||||
)
|
||||
|
||||
super.delete(objects)
|
||||
@@ -204,7 +204,7 @@ public final class SynchronousDataTransaction: BaseDataTransaction {
|
||||
|
||||
CoreStore.log(
|
||||
.Warning,
|
||||
message: "The closure for the \(typeName(self)) completed without being committed. All changes made within the transaction were discarded."
|
||||
message: "The closure for the \(cs_typeName(self)) completed without being committed. All changes made within the transaction were discarded."
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -224,11 +224,11 @@ public final class SynchronousDataTransaction: BaseDataTransaction {
|
||||
|
||||
CoreStore.assert(
|
||||
!self.isCommitted,
|
||||
"Attempted to rollback an already committed \(typeName(self))."
|
||||
"Attempted to rollback an already committed \(cs_typeName(self))."
|
||||
)
|
||||
CoreStore.assert(
|
||||
self.transactionQueue.isCurrentExecutionContext(),
|
||||
"Attempted to rollback a \(typeName(self)) outside its designated queue."
|
||||
"Attempted to rollback a \(cs_typeName(self)) outside its designated queue."
|
||||
)
|
||||
|
||||
self.context.reset()
|
||||
|
||||
@@ -70,7 +70,7 @@ public final class UnsafeDataTransaction: BaseDataTransaction {
|
||||
|
||||
CoreStore.assert(
|
||||
self.supportsUndo,
|
||||
"Attempted to rollback a \(typeName(self)) with Undo support disabled."
|
||||
"Attempted to rollback a \(cs_typeName(self)) with Undo support disabled."
|
||||
)
|
||||
self.context.rollback()
|
||||
}
|
||||
@@ -82,7 +82,7 @@ public final class UnsafeDataTransaction: BaseDataTransaction {
|
||||
|
||||
CoreStore.assert(
|
||||
self.supportsUndo,
|
||||
"Attempted to undo a \(typeName(self)) with Undo support disabled."
|
||||
"Attempted to undo a \(cs_typeName(self)) with Undo support disabled."
|
||||
)
|
||||
self.context.undo()
|
||||
}
|
||||
@@ -94,7 +94,7 @@ public final class UnsafeDataTransaction: BaseDataTransaction {
|
||||
|
||||
CoreStore.assert(
|
||||
self.supportsUndo,
|
||||
"Attempted to redo a \(typeName(self)) with Undo support disabled."
|
||||
"Attempted to redo a \(cs_typeName(self)) with Undo support disabled."
|
||||
)
|
||||
self.context.redo()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user