Merge branch 'develop' into corestore2_develop

Conflicts:
	CoreStore.podspec
	CoreStore/Info.plist
This commit is contained in:
John Rommel Estropia
2016-02-26 01:51:35 +09:00
4 changed files with 60 additions and 6 deletions

View File

@@ -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`.
*/
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>(
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
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>(
context: context,

View File

@@ -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.
- returns: a `SaveResult` containing the success or failure information
*/
public func commit() {
public func commitAndWait() -> SaveResult {
CoreStore.assert(
self.transactionQueue.isCurrentExecutionContext(),
@@ -52,7 +54,10 @@ public final class SynchronousDataTransaction: BaseDataTransaction {
)
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()
}
@available(*, deprecated=1.5.2, renamed="commitAndWait")
public func commit() {
self.commitAndWait()
}
// MARK: Internal

View File

@@ -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.
*/

View File

@@ -260,9 +260,9 @@ do {
completion: { (result) -> Void in
switch result {
case .Success(let persistentStore):
print("Successfully added sqlite store: \(persistentStore)"
print("Successfully added sqlite store: \(persistentStore)")
case .Failure(let error):
print("Failed adding sqlite store with error: \(error)"
print("Failed adding sqlite store with error: \(error)")
}
}
)