mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-01-18 15:07:00 +01:00
goodbye strongSelf
This commit is contained in:
@@ -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 }
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
@@ -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
|
||||
)
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user