From d60e09b136fe4610a23a7ffc9177832ec9410064 Mon Sep 17 00:00:00 2001 From: Sami Samhuri Date: Thu, 17 Feb 2022 21:02:01 -0800 Subject: [PATCH] Rename BlockOperation to EarthquakeBlockOperation --- Advanced NSOperations.xcodeproj/project.pbxproj | 9 +++++---- Earthquakes/EarthquakeTableViewController.swift | 2 +- .../EarthquakesTableViewController.swift | 17 +++++++++-------- ...ion.swift => EarthquakeBlockOperation.swift} | 2 +- 4 files changed, 16 insertions(+), 14 deletions(-) rename Earthquakes/Operations/{BlockOperation.swift => EarthquakeBlockOperation.swift} (97%) diff --git a/Advanced NSOperations.xcodeproj/project.pbxproj b/Advanced NSOperations.xcodeproj/project.pbxproj index 5860e80..f967e82 100644 --- a/Advanced NSOperations.xcodeproj/project.pbxproj +++ b/Advanced NSOperations.xcodeproj/project.pbxproj @@ -20,7 +20,7 @@ 55817C3A1B18FDF8001C0CE2 /* OperationQueue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 551B9C061AEB2D7800302388 /* OperationQueue.swift */; }; 55817C3B1B18FDF8001C0CE2 /* ExclusivityController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55CD4D201AF5C05300E3A9E3 /* ExclusivityController.swift */; }; 55817C3C1B18FDF8001C0CE2 /* Operation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 551B9C021AEB1CA900302388 /* Operation.swift */; }; - 55817C3D1B18FDF8001C0CE2 /* BlockOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55857B3A1AF20DE800219D5A /* BlockOperation.swift */; }; + 55817C3D1B18FDF8001C0CE2 /* EarthquakeBlockOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55857B3A1AF20DE800219D5A /* EarthquakeBlockOperation.swift */; }; 55817C3E1B18FDF8001C0CE2 /* GroupOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55727FB11AF2798C00EC6916 /* GroupOperation.swift */; }; 55817C3F1B18FDF8001C0CE2 /* URLSessionTaskOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55727FB91AF2849E00EC6916 /* URLSessionTaskOperation.swift */; }; 55817C401B18FDF8001C0CE2 /* LocationOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 553F50031B07FB5E005F991E /* LocationOperation.swift */; }; @@ -110,7 +110,7 @@ 55857B331AF2055600219D5A /* SilentCondition.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SilentCondition.swift; sourceTree = ""; }; 55857B351AF2077700219D5A /* CKContainer+Operations.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CKContainer+Operations.swift"; sourceTree = ""; }; 55857B381AF20CC700219D5A /* MutuallyExclusive.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MutuallyExclusive.swift; sourceTree = ""; }; - 55857B3A1AF20DE800219D5A /* BlockOperation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BlockOperation.swift; sourceTree = ""; }; + 55857B3A1AF20DE800219D5A /* EarthquakeBlockOperation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EarthquakeBlockOperation.swift; sourceTree = ""; }; 55857B3E1AF2116600219D5A /* NoCancelledDependencies.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NoCancelledDependencies.swift; sourceTree = ""; }; 55AD643C1B128CC3000EF5CB /* TimeoutObserver.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TimeoutObserver.swift; sourceTree = ""; }; 55CD4D201AF5C05300E3A9E3 /* ExclusivityController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExclusivityController.swift; sourceTree = ""; }; @@ -276,7 +276,7 @@ isa = PBXGroup; children = ( 551B9C021AEB1CA900302388 /* Operation.swift */, - 55857B3A1AF20DE800219D5A /* BlockOperation.swift */, + 55857B3A1AF20DE800219D5A /* EarthquakeBlockOperation.swift */, 55727FB11AF2798C00EC6916 /* GroupOperation.swift */, 55727FB91AF2849E00EC6916 /* URLSessionTaskOperation.swift */, 553F50031B07FB5E005F991E /* LocationOperation.swift */, @@ -355,6 +355,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, Base, ); @@ -427,7 +428,7 @@ 55E702681AFE61700032742F /* Earthquake.swift in Sources */, 55817C4F1B18FDF8001C0CE2 /* CalendarCondition.swift in Sources */, 55817C481B18FDF8001C0CE2 /* NegatedCondition.swift in Sources */, - 55817C3D1B18FDF8001C0CE2 /* BlockOperation.swift in Sources */, + 55817C3D1B18FDF8001C0CE2 /* EarthquakeBlockOperation.swift in Sources */, 55817C471B18FDF8001C0CE2 /* SilentCondition.swift in Sources */, 55E7021D1AFC38920032742F /* EarthquakeTableViewController.swift in Sources */, 55817C451B18FDF8001C0CE2 /* OperationErrors.swift in Sources */, diff --git a/Earthquakes/EarthquakeTableViewController.swift b/Earthquakes/EarthquakeTableViewController.swift index eb91c02..b457632 100644 --- a/Earthquakes/EarthquakeTableViewController.swift +++ b/Earthquakes/EarthquakeTableViewController.swift @@ -92,7 +92,7 @@ class EarthquakeTableViewController: UITableViewController { an `Operation`, we can make it mutually exclusive with other operations that modify the view controller hierarchy. */ - let shareOperation = BlockOperation { (continuation: Void -> Void) in + let shareOperation = EarthquakeBlockOperation { (continuation: Void -> Void) in dispatch_async(dispatch_get_main_queue()) { let shareSheet = UIActivityViewController(activityItems: items, applicationActivities: nil) diff --git a/Earthquakes/EarthquakesTableViewController.swift b/Earthquakes/EarthquakesTableViewController.swift index 99c0030..2242957 100644 --- a/Earthquakes/EarthquakesTableViewController.swift +++ b/Earthquakes/EarthquakesTableViewController.swift @@ -64,24 +64,25 @@ class EarthquakesTableViewController: UITableViewController { override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { /* - Instead of performing the segue directly, we can wrap it in a `BlockOperation`. - This allows us to attach conditions to the operation. For example, you - could make it so that you could only perform the segue if the network - is reachable and you have access to the user's Photos library. + Instead of performing the segue directly, we can wrap it in a + `EarthquakeBlockOperation`. This allows us to attach conditions to the + operation. For example, you could make it so that you could only perform + the segue if the network is reachable and you have access to the user's + Photos library. If you decide to use this pattern in your apps, choose conditions that are sensible and do not place onerous requirements on the user. - It's also worth noting that the Observer attached to the `BlockOperation` - will cause the tableview row to be deselected automatically if the - `Operation` fails. + It's also worth noting that the Observer attached to the + `EarthquakeBlockOperation` will cause the tableview row to be deselected + automatically if the `EarthquakeOperation` fails. You may choose to add your own observer to introspect the errors reported as the operation finishes. Doing so would allow you to present a message to the user about why you were unable to perform the requested action. */ - let operation = BlockOperation { + let operation = EarthquakeBlockOperation { self.performSegueWithIdentifier("showEarthquake", sender: nil) } diff --git a/Earthquakes/Operations/BlockOperation.swift b/Earthquakes/Operations/EarthquakeBlockOperation.swift similarity index 97% rename from Earthquakes/Operations/BlockOperation.swift rename to Earthquakes/Operations/EarthquakeBlockOperation.swift index 4a7f015..5687b8f 100644 --- a/Earthquakes/Operations/BlockOperation.swift +++ b/Earthquakes/Operations/EarthquakeBlockOperation.swift @@ -12,7 +12,7 @@ import Foundation typealias OperationBlock = (Void -> Void) -> Void /// A sublcass of `Operation` to execute a closure. -class BlockOperation: Operation { +class EarthquakeBlockOperation: Operation { private let block: OperationBlock? /**