Rename BlockOperation to EarthquakeBlockOperation

This commit is contained in:
Sami Samhuri 2022-02-17 21:02:01 -08:00
parent 8b89ba572e
commit d60e09b136
No known key found for this signature in database
GPG key ID: 4B4195422742FC16
4 changed files with 16 additions and 14 deletions

View file

@ -20,7 +20,7 @@
55817C3A1B18FDF8001C0CE2 /* OperationQueue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 551B9C061AEB2D7800302388 /* OperationQueue.swift */; }; 55817C3A1B18FDF8001C0CE2 /* OperationQueue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 551B9C061AEB2D7800302388 /* OperationQueue.swift */; };
55817C3B1B18FDF8001C0CE2 /* ExclusivityController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55CD4D201AF5C05300E3A9E3 /* ExclusivityController.swift */; }; 55817C3B1B18FDF8001C0CE2 /* ExclusivityController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55CD4D201AF5C05300E3A9E3 /* ExclusivityController.swift */; };
55817C3C1B18FDF8001C0CE2 /* Operation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 551B9C021AEB1CA900302388 /* Operation.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 */; }; 55817C3E1B18FDF8001C0CE2 /* GroupOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55727FB11AF2798C00EC6916 /* GroupOperation.swift */; };
55817C3F1B18FDF8001C0CE2 /* URLSessionTaskOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55727FB91AF2849E00EC6916 /* URLSessionTaskOperation.swift */; }; 55817C3F1B18FDF8001C0CE2 /* URLSessionTaskOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55727FB91AF2849E00EC6916 /* URLSessionTaskOperation.swift */; };
55817C401B18FDF8001C0CE2 /* LocationOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 553F50031B07FB5E005F991E /* LocationOperation.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 = "<group>"; }; 55857B331AF2055600219D5A /* SilentCondition.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SilentCondition.swift; sourceTree = "<group>"; };
55857B351AF2077700219D5A /* CKContainer+Operations.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CKContainer+Operations.swift"; sourceTree = "<group>"; }; 55857B351AF2077700219D5A /* CKContainer+Operations.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CKContainer+Operations.swift"; sourceTree = "<group>"; };
55857B381AF20CC700219D5A /* MutuallyExclusive.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MutuallyExclusive.swift; sourceTree = "<group>"; }; 55857B381AF20CC700219D5A /* MutuallyExclusive.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MutuallyExclusive.swift; sourceTree = "<group>"; };
55857B3A1AF20DE800219D5A /* BlockOperation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BlockOperation.swift; sourceTree = "<group>"; }; 55857B3A1AF20DE800219D5A /* EarthquakeBlockOperation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EarthquakeBlockOperation.swift; sourceTree = "<group>"; };
55857B3E1AF2116600219D5A /* NoCancelledDependencies.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NoCancelledDependencies.swift; sourceTree = "<group>"; }; 55857B3E1AF2116600219D5A /* NoCancelledDependencies.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NoCancelledDependencies.swift; sourceTree = "<group>"; };
55AD643C1B128CC3000EF5CB /* TimeoutObserver.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TimeoutObserver.swift; sourceTree = "<group>"; }; 55AD643C1B128CC3000EF5CB /* TimeoutObserver.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TimeoutObserver.swift; sourceTree = "<group>"; };
55CD4D201AF5C05300E3A9E3 /* ExclusivityController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExclusivityController.swift; sourceTree = "<group>"; }; 55CD4D201AF5C05300E3A9E3 /* ExclusivityController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExclusivityController.swift; sourceTree = "<group>"; };
@ -276,7 +276,7 @@
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
551B9C021AEB1CA900302388 /* Operation.swift */, 551B9C021AEB1CA900302388 /* Operation.swift */,
55857B3A1AF20DE800219D5A /* BlockOperation.swift */, 55857B3A1AF20DE800219D5A /* EarthquakeBlockOperation.swift */,
55727FB11AF2798C00EC6916 /* GroupOperation.swift */, 55727FB11AF2798C00EC6916 /* GroupOperation.swift */,
55727FB91AF2849E00EC6916 /* URLSessionTaskOperation.swift */, 55727FB91AF2849E00EC6916 /* URLSessionTaskOperation.swift */,
553F50031B07FB5E005F991E /* LocationOperation.swift */, 553F50031B07FB5E005F991E /* LocationOperation.swift */,
@ -355,6 +355,7 @@
developmentRegion = English; developmentRegion = English;
hasScannedForEncodings = 0; hasScannedForEncodings = 0;
knownRegions = ( knownRegions = (
English,
en, en,
Base, Base,
); );
@ -427,7 +428,7 @@
55E702681AFE61700032742F /* Earthquake.swift in Sources */, 55E702681AFE61700032742F /* Earthquake.swift in Sources */,
55817C4F1B18FDF8001C0CE2 /* CalendarCondition.swift in Sources */, 55817C4F1B18FDF8001C0CE2 /* CalendarCondition.swift in Sources */,
55817C481B18FDF8001C0CE2 /* NegatedCondition.swift in Sources */, 55817C481B18FDF8001C0CE2 /* NegatedCondition.swift in Sources */,
55817C3D1B18FDF8001C0CE2 /* BlockOperation.swift in Sources */, 55817C3D1B18FDF8001C0CE2 /* EarthquakeBlockOperation.swift in Sources */,
55817C471B18FDF8001C0CE2 /* SilentCondition.swift in Sources */, 55817C471B18FDF8001C0CE2 /* SilentCondition.swift in Sources */,
55E7021D1AFC38920032742F /* EarthquakeTableViewController.swift in Sources */, 55E7021D1AFC38920032742F /* EarthquakeTableViewController.swift in Sources */,
55817C451B18FDF8001C0CE2 /* OperationErrors.swift in Sources */, 55817C451B18FDF8001C0CE2 /* OperationErrors.swift in Sources */,

View file

@ -92,7 +92,7 @@ class EarthquakeTableViewController: UITableViewController {
an `Operation`, we can make it mutually exclusive with other operations an `Operation`, we can make it mutually exclusive with other operations
that modify the view controller hierarchy. 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()) { dispatch_async(dispatch_get_main_queue()) {
let shareSheet = UIActivityViewController(activityItems: items, applicationActivities: nil) let shareSheet = UIActivityViewController(activityItems: items, applicationActivities: nil)

View file

@ -64,24 +64,25 @@ class EarthquakesTableViewController: UITableViewController {
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
/* /*
Instead of performing the segue directly, we can wrap it in a `BlockOperation`. Instead of performing the segue directly, we can wrap it in a
This allows us to attach conditions to the operation. For example, you `EarthquakeBlockOperation`. This allows us to attach conditions to the
could make it so that you could only perform the segue if the network operation. For example, you could make it so that you could only perform
is reachable and you have access to the user's Photos library. 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 If you decide to use this pattern in your apps, choose conditions that
are sensible and do not place onerous requirements on the user. are sensible and do not place onerous requirements on the user.
It's also worth noting that the Observer attached to the `BlockOperation` It's also worth noting that the Observer attached to the
will cause the tableview row to be deselected automatically if the `EarthquakeBlockOperation` will cause the tableview row to be deselected
`Operation` fails. automatically if the `EarthquakeOperation` fails.
You may choose to add your own observer to introspect the errors reported 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 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. to the user about why you were unable to perform the requested action.
*/ */
let operation = BlockOperation { let operation = EarthquakeBlockOperation {
self.performSegueWithIdentifier("showEarthquake", sender: nil) self.performSegueWithIdentifier("showEarthquake", sender: nil)
} }

View file

@ -12,7 +12,7 @@ import Foundation
typealias OperationBlock = (Void -> Void) -> Void typealias OperationBlock = (Void -> Void) -> Void
/// A sublcass of `Operation` to execute a closure. /// A sublcass of `Operation` to execute a closure.
class BlockOperation: Operation { class EarthquakeBlockOperation: Operation {
private let block: OperationBlock? private let block: OperationBlock?
/** /**