mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-03-22 09:29:45 +01:00
Merge branch 'develop' into corestore2_develop
Conflicts: CoreStore.podspec CoreStore/Info.plist
This commit is contained in:
@@ -34,7 +34,7 @@ public extension NSFetchedResultsController {
|
|||||||
/**
|
/**
|
||||||
Utility for creating an `NSFetchedResultsController` from a `DataStack`. This is useful to partially support Objective-C classes by passing an `NSFetchedResultsController` instance instead of a `ListMonitor`.
|
Utility for creating an `NSFetchedResultsController` from a `DataStack`. This is useful to partially support Objective-C classes by passing an `NSFetchedResultsController` instance instead of a `ListMonitor`.
|
||||||
*/
|
*/
|
||||||
public func createForStack<T: NSManagedObject>(dataStack: DataStack, fetchRequest: NSFetchRequest, from: From<T>? = nil, sectionBy: SectionBy? = nil, fetchClauses: [FetchClause]) -> NSFetchedResultsController {
|
public static func createForStack<T: NSManagedObject>(dataStack: DataStack, fetchRequest: NSFetchRequest, from: From<T>? = nil, sectionBy: SectionBy? = nil, fetchClauses: [FetchClause]) -> NSFetchedResultsController {
|
||||||
|
|
||||||
return CoreStoreFetchedResultsController<T>(
|
return CoreStoreFetchedResultsController<T>(
|
||||||
context: dataStack.mainContext,
|
context: dataStack.mainContext,
|
||||||
@@ -45,10 +45,41 @@ public extension NSFetchedResultsController {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@available(*, deprecated=1.5.2, message="Use NSFetchedResultsController.createForStack(_:fetchRequest:from:sectionBy:fetchClauses:) to create NSFetchedResultsControllers directly")
|
||||||
|
public convenience init<T: NSManagedObject>(dataStack: DataStack, fetchRequest: NSFetchRequest, from: From<T>? = nil, sectionBy: SectionBy? = nil, fetchClauses: [FetchClause]) {
|
||||||
|
|
||||||
|
let context = dataStack.mainContext
|
||||||
|
from?.applyToFetchRequest(fetchRequest, context: context, applyAffectedStores: false)
|
||||||
|
for clause in fetchClauses {
|
||||||
|
|
||||||
|
clause.applyToFetchRequest(fetchRequest)
|
||||||
|
}
|
||||||
|
|
||||||
|
if let from = from {
|
||||||
|
|
||||||
|
from.applyAffectedStoresForFetchedRequest(fetchRequest, context: context)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
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.")
|
||||||
|
}
|
||||||
|
from.applyAffectedStoresForFetchedRequest(fetchRequest, context: context)
|
||||||
|
}
|
||||||
|
|
||||||
|
self.init(
|
||||||
|
fetchRequest: fetchRequest,
|
||||||
|
managedObjectContext: context,
|
||||||
|
sectionNameKeyPath: sectionBy?.sectionKeyPath,
|
||||||
|
cacheName: nil
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// MARK: Internal
|
// MARK: Internal
|
||||||
|
|
||||||
internal func createFromContext<T: NSManagedObject>(context: NSManagedObjectContext, fetchRequest: NSFetchRequest, from: From<T>? = nil, sectionBy: SectionBy? = nil, fetchClauses: [FetchClause]) -> NSFetchedResultsController {
|
internal static func createFromContext<T: NSManagedObject>(context: NSManagedObjectContext, fetchRequest: NSFetchRequest, from: From<T>? = nil, sectionBy: SectionBy? = nil, fetchClauses: [FetchClause]) -> NSFetchedResultsController {
|
||||||
|
|
||||||
return CoreStoreFetchedResultsController<T>(
|
return CoreStoreFetchedResultsController<T>(
|
||||||
context: context,
|
context: context,
|
||||||
|
|||||||
@@ -39,8 +39,10 @@ public final class SynchronousDataTransaction: BaseDataTransaction {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
Saves the transaction changes and waits for completion synchronously. This method should not be used after the `commit()` method was already called once.
|
Saves the transaction changes and waits for completion synchronously. This method should not be used after the `commit()` method was already called once.
|
||||||
|
|
||||||
|
- returns: a `SaveResult` containing the success or failure information
|
||||||
*/
|
*/
|
||||||
public func commit() {
|
public func commitAndWait() -> SaveResult {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
self.transactionQueue.isCurrentExecutionContext(),
|
self.transactionQueue.isCurrentExecutionContext(),
|
||||||
@@ -52,7 +54,10 @@ public final class SynchronousDataTransaction: BaseDataTransaction {
|
|||||||
)
|
)
|
||||||
|
|
||||||
self.isCommitted = true
|
self.isCommitted = true
|
||||||
self.result = self.context.saveSynchronously()
|
|
||||||
|
let result = self.context.saveSynchronously()
|
||||||
|
self.result = result
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -197,6 +202,12 @@ public final class SynchronousDataTransaction: BaseDataTransaction {
|
|||||||
self.context.reset()
|
self.context.reset()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@available(*, deprecated=1.5.2, renamed="commitAndWait")
|
||||||
|
public func commit() {
|
||||||
|
|
||||||
|
self.commitAndWait()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// MARK: Internal
|
// MARK: Internal
|
||||||
|
|
||||||
|
|||||||
@@ -55,6 +55,18 @@ public final class UnsafeDataTransaction: BaseDataTransaction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Saves the transaction changes and waits for completion synchronously. For a `UnsafeDataTransaction`, multiple commits are allowed, although it is the developer's responsibility to ensure a reasonable leeway to prevent blocking the main thread.
|
||||||
|
|
||||||
|
- returns: a `SaveResult` containing the success or failure information
|
||||||
|
*/
|
||||||
|
public func commitAndWait() -> SaveResult {
|
||||||
|
|
||||||
|
let result = self.context.saveSynchronously()
|
||||||
|
self.result = result
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Rolls back the transaction.
|
Rolls back the transaction.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -260,9 +260,9 @@ do {
|
|||||||
completion: { (result) -> Void in
|
completion: { (result) -> Void in
|
||||||
switch result {
|
switch result {
|
||||||
case .Success(let persistentStore):
|
case .Success(let persistentStore):
|
||||||
print("Successfully added sqlite store: \(persistentStore)"
|
print("Successfully added sqlite store: \(persistentStore)")
|
||||||
case .Failure(let error):
|
case .Failure(let error):
|
||||||
print("Failed adding sqlite store with error: \(error)"
|
print("Failed adding sqlite store with error: \(error)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user