From c1e087b8c16f8ac342abe8d62b10761422b3a0ff Mon Sep 17 00:00:00 2001 From: John Estropia Date: Thu, 3 Mar 2016 12:51:56 +0900 Subject: [PATCH] goodbye strongSelf --- CoreStore/Migrating/DataStack+Migration.swift | 7 ++- CoreStore/Observing/ListMonitor.swift | 52 +++++++++---------- CoreStore/Observing/ObjectMonitor.swift | 14 ++--- .../MigrationsDemoViewController.swift | 22 ++++---- 4 files changed, 47 insertions(+), 48 deletions(-) diff --git a/CoreStore/Migrating/DataStack+Migration.swift b/CoreStore/Migrating/DataStack+Migration.swift index fe2621d..0799c22 100644 --- a/CoreStore/Migrating/DataStack+Migration.swift +++ b/CoreStore/Migrating/DataStack+Migration.swift @@ -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 } } } ) diff --git a/CoreStore/Observing/ListMonitor.swift b/CoreStore/Observing/ListMonitor.swift index 07ed682..9ba11b8 100644 --- a/CoreStore/Observing/ListMonitor.swift +++ b/CoreStore/Observing/ListMonitor.swift @@ -894,41 +894,41 @@ public final class ListMonitor { 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 { 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 { 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 { 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 { 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 { 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 { return } callback( - monitor: strongSelf, + monitor: self, sectionInfo: sectionInfo, sectionIndex: sectionIndex ) diff --git a/CoreStore/Observing/ObjectMonitor.swift b/CoreStore/Observing/ObjectMonitor.swift index c3f16b8..9d86786 100644 --- a/CoreStore/Observing/ObjectMonitor.swift +++ b/CoreStore/Observing/ObjectMonitor.swift @@ -113,12 +113,12 @@ public final class ObjectMonitor { 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() @@ -130,7 +130,7 @@ public final class ObjectMonitor { } } - strongSelf.lastCommittedAttributes = currentCommitedAttributes + self.lastCommittedAttributes = currentCommitedAttributes observer.objectMonitor( monitor, didUpdateObject: object, @@ -225,11 +225,11 @@ public final class ObjectMonitor { 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 { 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, diff --git a/CoreStoreDemo/CoreStoreDemo/MIgrations Demo/MigrationsDemoViewController.swift b/CoreStoreDemo/CoreStoreDemo/MIgrations Demo/MigrationsDemoViewController.swift index 6db77c3..5f3f5e4 100644 --- a/CoreStoreDemo/CoreStoreDemo/MIgrations Demo/MigrationsDemoViewController.swift +++ b/CoreStoreDemo/CoreStoreDemo/MIgrations Demo/MigrationsDemoViewController.swift @@ -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(.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()