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

View File

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

View File

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

View File

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