goodbye strongSelf

This commit is contained in:
John Estropia
2016-03-03 12:51:56 +09:00
parent ad1ebb3501
commit c1e087b8c1
4 changed files with 47 additions and 48 deletions

View File

@@ -402,7 +402,7 @@ public extension DataStack {
operations.append(
NSBlockOperation { [weak self] in
guard let strongSelf = self where !cancelled else {
guard let `self` = self where !cancelled else {
return
}
@@ -411,7 +411,7 @@ public extension DataStack {
do {
try strongSelf.startMigrationForSQLiteStore(
try self.startMigrationForSQLiteStore(
fileURL: fileURL,
sourceModel: sourceModel,
destinationModel: destinationModel,
@@ -428,8 +428,7 @@ public extension DataStack {
GCDQueue.Main.async {
withExtendedLifetime(childProgress) { (_: NSProgress) -> Void in }
return
_ = withExtendedLifetime(childProgress) { (_: NSProgress) -> Void in }
}
}
)

View File

@@ -894,41 +894,41 @@ public final class ListMonitor<T: NSManagedObject> {
self.taskGroup.notify(.Main) { [weak self] () -> Void in
guard let strongSelf = self else {
guard let `self` = self else {
return
}
strongSelf.fetchedResultsControllerDelegate.enabled = false
self.fetchedResultsControllerDelegate.enabled = false
let fetchRequest = strongSelf.fetchedResultsController.fetchRequest
let fetchRequest = self.fetchedResultsController.fetchRequest
for clause in fetchClauses {
clause.applyToFetchRequest(fetchRequest)
}
strongSelf.transactionQueue.async {
self.transactionQueue.async { [weak self] in
guard let strongSelf = self else {
guard let `self` = self else {
return
}
try! strongSelf.fetchedResultsController.performFetchFromSpecifiedStores()
try! self.fetchedResultsController.performFetchFromSpecifiedStores()
GCDQueue.Main.async { () -> Void in
GCDQueue.Main.async { [weak self] () -> Void in
guard let strongSelf = self else {
guard let `self` = self else {
return
}
strongSelf.fetchedResultsControllerDelegate.enabled = true
strongSelf.isPendingRefetch = false
self.fetchedResultsControllerDelegate.enabled = true
self.isPendingRefetch = false
NSNotificationCenter.defaultCenter().postNotificationName(
ListMonitorDidRefetchListNotification,
object: strongSelf
object: self
)
}
}
@@ -1033,19 +1033,19 @@ public final class ListMonitor<T: NSManagedObject> {
object: coordinator,
closure: { [weak self] (note) -> Void in
guard let strongSelf = self else {
guard let `self` = self else {
return
}
strongSelf.isPersistentStoreChanging = true
self.isPersistentStoreChanging = true
guard let removedStores = (note.userInfo?[NSRemovedPersistentStoresKey] as? [NSPersistentStore]).flatMap(Set.init)
where !Set(strongSelf.fetchedResultsController.fetchRequest.affectedStores ?? []).intersect(removedStores).isEmpty else {
where !Set(self.fetchedResultsController.fetchRequest.affectedStores ?? []).intersect(removedStores).isEmpty else {
return
}
strongSelf.refetch(fetchClauses)
self.refetch(fetchClauses)
}
)
@@ -1054,25 +1054,25 @@ public final class ListMonitor<T: NSManagedObject> {
object: coordinator,
closure: { [weak self] (note) -> Void in
guard let strongSelf = self else {
guard let `self` = self else {
return
}
if !strongSelf.isPendingRefetch {
if !self.isPendingRefetch {
let previousStores = Set(strongSelf.fetchedResultsController.fetchRequest.affectedStores ?? [])
let previousStores = Set(self.fetchedResultsController.fetchRequest.affectedStores ?? [])
let currentStores = previousStores
.subtract(note.userInfo?[NSRemovedPersistentStoresKey] as? [NSPersistentStore] ?? [])
.union(note.userInfo?[NSAddedPersistentStoresKey] as? [NSPersistentStore] ?? [])
if previousStores != currentStores {
strongSelf.refetch(fetchClauses)
self.refetch(fetchClauses)
}
}
strongSelf.isPersistentStoreChanging = false
self.isPersistentStoreChanging = false
}
)
@@ -1152,11 +1152,11 @@ public final class ListMonitor<T: NSManagedObject> {
object: self,
closure: { [weak self] (note) -> Void in
guard let strongSelf = self else {
guard let `self` = self else {
return
}
callback(monitor: strongSelf)
callback(monitor: self)
}
),
forKey: notificationKey,
@@ -1172,14 +1172,14 @@ public final class ListMonitor<T: NSManagedObject> {
object: self,
closure: { [weak self] (note) -> Void in
guard let strongSelf = self,
guard let `self` = self,
let userInfo = note.userInfo,
let object = userInfo[UserInfoKeyObject] as? T else {
return
}
callback(
monitor: strongSelf,
monitor: self,
object: object,
indexPath: userInfo[UserInfoKeyIndexPath] as? NSIndexPath,
newIndexPath: userInfo[UserInfoKeyNewIndexPath] as? NSIndexPath
@@ -1199,7 +1199,7 @@ public final class ListMonitor<T: NSManagedObject> {
object: self,
closure: { [weak self] (note) -> Void in
guard let strongSelf = self,
guard let `self` = self,
let userInfo = note.userInfo,
let sectionInfo = userInfo[UserInfoKeySectionInfo] as? NSFetchedResultsSectionInfo,
let sectionIndex = (userInfo[UserInfoKeySectionIndex] as? NSNumber)?.integerValue else {
@@ -1207,7 +1207,7 @@ public final class ListMonitor<T: NSManagedObject> {
return
}
callback(
monitor: strongSelf,
monitor: self,
sectionInfo: sectionInfo,
sectionIndex: sectionIndex
)

View File

@@ -113,12 +113,12 @@ public final class ObjectMonitor<T: NSManagedObject> {
toObserver: observer,
callback: { [weak self, weak observer] (monitor, object) -> Void in
guard let strongSelf = self, let observer = observer else {
guard let `self` = self, let observer = observer else {
return
}
let previousCommitedAttributes = strongSelf.lastCommittedAttributes
let previousCommitedAttributes = self.lastCommittedAttributes
let currentCommitedAttributes = object.committedValuesForKeys(nil) as! [String: NSObject]
var changedKeys = Set<String>()
@@ -130,7 +130,7 @@ public final class ObjectMonitor<T: NSManagedObject> {
}
}
strongSelf.lastCommittedAttributes = currentCommitedAttributes
self.lastCommittedAttributes = currentCommitedAttributes
observer.objectMonitor(
monitor,
didUpdateObject: object,
@@ -225,11 +225,11 @@ public final class ObjectMonitor<T: NSManagedObject> {
object: self,
closure: { [weak self] (note) -> Void in
guard let strongSelf = self else {
guard let `self` = self else {
return
}
callback(monitor: strongSelf)
callback(monitor: self)
}
),
forKey: notificationKey,
@@ -245,13 +245,13 @@ public final class ObjectMonitor<T: NSManagedObject> {
object: self,
closure: { [weak self] (note) -> Void in
guard let strongSelf = self,
guard let `self` = self,
let userInfo = note.userInfo,
let object = userInfo[UserInfoKeyObject] as? T else {
return
}
callback(monitor: strongSelf, object: object)
callback(monitor: self, object: object)
}
),
forKey: notificationKey,

View File

@@ -162,27 +162,27 @@ class MigrationsDemoViewController: UIViewController {
fileName: "MigrationDemo.sqlite",
completion: { [weak self] (result) -> Void in
guard let strongSelf = self else {
guard let `self` = self else {
return
}
guard case .Success = result else {
strongSelf.setEnabled(true)
self.setEnabled(true)
return
}
strongSelf.setDataStack(dataStack, model: model, scrollToSelection: true)
self.setDataStack(dataStack, model: model, scrollToSelection: true)
let count = dataStack.queryValue(From(model.entityType), Select<Int>(.Count("dna")))
if count > 0 {
strongSelf.setEnabled(true)
self.setEnabled(true)
}
else {
dataStack.beginAsynchronous { (transaction) -> Void in
dataStack.beginAsynchronous { [weak self] (transaction) -> Void in
for i: Int64 in 1 ..< 10000 {
@@ -355,16 +355,16 @@ extension MigrationsDemoViewController: UITableViewDataSource, UITableViewDelega
cell.dnaLabel?.text = "DNA: \(dna)"
cell.mutateButtonHandler = { [weak self] _ -> Void in
guard let strongSelf = self,
let dataStack = strongSelf.dataStack,
let organism = strongSelf.listMonitor?[indexPath] else {
guard let `self` = self,
let dataStack = self.dataStack,
let organism = self.listMonitor?[indexPath] else {
return
}
strongSelf.setSelectedIndexPath(indexPath, scrollToSelection: false)
strongSelf.setEnabled(false)
dataStack.beginAsynchronous { (transaction) -> Void in
self.setSelectedIndexPath(indexPath, scrollToSelection: false)
self.setEnabled(false)
dataStack.beginAsynchronous { [weak self] (transaction) -> Void in
let organism = transaction.edit(organism) as! OrganismProtocol
organism.mutate()