Update type names and comments

This commit is contained in:
Sami Samhuri 2022-02-17 22:31:08 -08:00
parent 77f9ae6860
commit 1b4ded021d
No known key found for this signature in database
GPG key ID: 4B4195422742FC16
27 changed files with 96 additions and 92 deletions

View file

@ -19,13 +19,13 @@
553F50161B08E98A005F991E /* LoadModelOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 553F50151B08E98A005F991E /* LoadModelOperation.swift */; }; 553F50161B08E98A005F991E /* LoadModelOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 553F50151B08E98A005F991E /* LoadModelOperation.swift */; };
55817C3A1B18FDF8001C0CE2 /* EarthquakeOperationQueue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 551B9C061AEB2D7800302388 /* EarthquakeOperationQueue.swift */; }; 55817C3A1B18FDF8001C0CE2 /* EarthquakeOperationQueue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 551B9C061AEB2D7800302388 /* EarthquakeOperationQueue.swift */; };
55817C3B1B18FDF8001C0CE2 /* ExclusivityController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55CD4D201AF5C05300E3A9E3 /* ExclusivityController.swift */; }; 55817C3B1B18FDF8001C0CE2 /* ExclusivityController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55CD4D201AF5C05300E3A9E3 /* ExclusivityController.swift */; };
55817C3D1B18FDF8001C0CE2 /* EarthquakeBlockOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55857B3A1AF20DE800219D5A /* EarthquakeBlockOperation.swift */; };
55817C3C1B18FDF8001C0CE2 /* EarthquakeOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 551B9C021AEB1CA900302388 /* EarthquakeOperation.swift */; }; 55817C3C1B18FDF8001C0CE2 /* EarthquakeOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 551B9C021AEB1CA900302388 /* EarthquakeOperation.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 */; };
55817C411B18FDF8001C0CE2 /* DelayOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 553F50131B0832D2005F991E /* DelayOperation.swift */; }; 55817C411B18FDF8001C0CE2 /* DelayOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 553F50131B0832D2005F991E /* DelayOperation.swift */; };
55817C421B18FDF8001C0CE2 /* OperationObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 553F50051B081760005F991E /* OperationObserver.swift */; }; 55817C421B18FDF8001C0CE2 /* EarthquakeOperationObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 553F50051B081760005F991E /* EarthquakeOperationObserver.swift */; };
55817C431B18FDF8001C0CE2 /* BlockObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 553F50081B0817D2005F991E /* BlockObserver.swift */; }; 55817C431B18FDF8001C0CE2 /* BlockObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 553F50081B0817D2005F991E /* BlockObserver.swift */; };
55817C441B18FDF8001C0CE2 /* TimeoutObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55AD643C1B128CC3000EF5CB /* TimeoutObserver.swift */; }; 55817C441B18FDF8001C0CE2 /* TimeoutObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55AD643C1B128CC3000EF5CB /* TimeoutObserver.swift */; };
55817C451B18FDF8001C0CE2 /* OperationErrors.swift in Sources */ = {isa = PBXBuildFile; fileRef = 553F2D651B00041100BF4093 /* OperationErrors.swift */; }; 55817C451B18FDF8001C0CE2 /* OperationErrors.swift in Sources */ = {isa = PBXBuildFile; fileRef = 553F2D651B00041100BF4093 /* OperationErrors.swift */; };
@ -96,7 +96,7 @@
553C5AC61AF6D2EB002FC47A /* HealthCondition.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HealthCondition.swift; sourceTree = "<group>"; }; 553C5AC61AF6D2EB002FC47A /* HealthCondition.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HealthCondition.swift; sourceTree = "<group>"; };
553F2D651B00041100BF4093 /* OperationErrors.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OperationErrors.swift; sourceTree = "<group>"; }; 553F2D651B00041100BF4093 /* OperationErrors.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OperationErrors.swift; sourceTree = "<group>"; };
553F50031B07FB5E005F991E /* LocationOperation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LocationOperation.swift; sourceTree = "<group>"; }; 553F50031B07FB5E005F991E /* LocationOperation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LocationOperation.swift; sourceTree = "<group>"; };
553F50051B081760005F991E /* OperationObserver.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OperationObserver.swift; sourceTree = "<group>"; }; 553F50051B081760005F991E /* EarthquakeOperationObserver.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EarthquakeOperationObserver.swift; sourceTree = "<group>"; };
553F50081B0817D2005F991E /* BlockObserver.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BlockObserver.swift; sourceTree = "<group>"; }; 553F50081B0817D2005F991E /* BlockObserver.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BlockObserver.swift; sourceTree = "<group>"; };
553F500E1B081A9D005F991E /* NetworkObserver.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NetworkObserver.swift; sourceTree = "<group>"; }; 553F500E1B081A9D005F991E /* NetworkObserver.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NetworkObserver.swift; sourceTree = "<group>"; };
553F50101B082BCF005F991E /* BackgroundObserver.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BackgroundObserver.swift; sourceTree = "<group>"; }; 553F50101B082BCF005F991E /* BackgroundObserver.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BackgroundObserver.swift; sourceTree = "<group>"; };
@ -227,7 +227,7 @@
553F50071B0817BB005F991E /* Observers */ = { 553F50071B0817BB005F991E /* Observers */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
553F50051B081760005F991E /* OperationObserver.swift */, 553F50051B081760005F991E /* EarthquakeOperationObserver.swift */,
553F50081B0817D2005F991E /* BlockObserver.swift */, 553F50081B0817D2005F991E /* BlockObserver.swift */,
55AD643C1B128CC3000EF5CB /* TimeoutObserver.swift */, 55AD643C1B128CC3000EF5CB /* TimeoutObserver.swift */,
); );
@ -417,7 +417,7 @@
55817C3E1B18FDF8001C0CE2 /* GroupOperation.swift in Sources */, 55817C3E1B18FDF8001C0CE2 /* GroupOperation.swift in Sources */,
55817C491B18FDF8001C0CE2 /* NoCancelledDependencies.swift in Sources */, 55817C491B18FDF8001C0CE2 /* NoCancelledDependencies.swift in Sources */,
55817C581B18FDF8001C0CE2 /* UIUserNotifications+Operations.swift in Sources */, 55817C581B18FDF8001C0CE2 /* UIUserNotifications+Operations.swift in Sources */,
55817C421B18FDF8001C0CE2 /* OperationObserver.swift in Sources */, 55817C421B18FDF8001C0CE2 /* EarthquakeOperationObserver.swift in Sources */,
5521B4821B700C87007089CE /* NSLock+Operations.swift in Sources */, 5521B4821B700C87007089CE /* NSLock+Operations.swift in Sources */,
553F500F1B081A9D005F991E /* NetworkObserver.swift in Sources */, 553F500F1B081A9D005F991E /* NetworkObserver.swift in Sources */,
55817C551B18FDF8001C0CE2 /* Dictionary+Operations.swift in Sources */, 55817C551B18FDF8001C0CE2 /* Dictionary+Operations.swift in Sources */,

View file

@ -9,13 +9,13 @@ Contains the code related to automatic background tasks
import UIKit import UIKit
/** /**
`BackgroundObserver` is an `OperationObserver` that will automatically begin `BackgroundObserver` is an `EarthquakeOperationObserver` that will
and end a background task if the application transitions to the background. automatically begin and end a background task if the application transitions to the
This would be useful if you had a vital `Operation` whose execution *must* complete, background. This would be useful if you had a vital `EarthquakeOperation`
regardless of the activation state of the app. Some kinds network connections whose execution *must* complete, regardless of the activation state of the app.
may fall in to this category, for example. Some kinds network connections may fall in to this category, for example.
*/ */
class BackgroundObserver: NSObject, OperationObserver { class BackgroundObserver: NSObject, EarthquakeOperationObserver {
// MARK: Properties // MARK: Properties
private var identifier = UIBackgroundTaskIdentifier.invalid private var identifier = UIBackgroundTaskIdentifier.invalid

View file

@ -89,7 +89,7 @@ class EarthquakeTableViewController: UITableViewController {
/* /*
We could present the share sheet manually, but by putting it inside We could present the share sheet manually, but by putting it inside
an `Operation`, we can make it mutually exclusive with other operations an `EarthquakeOperation`, we can make it mutually exclusive with other operations
that modify the view controller hierarchy. that modify the view controller hierarchy.
*/ */
let shareOperation = EarthquakeBlockOperation { (continuation: @escaping () -> Void) in let shareOperation = EarthquakeBlockOperation { (continuation: @escaping () -> Void) in

View file

@ -8,7 +8,7 @@ This file sets up the operations to download and parse earthquake data. It will
import CoreData import CoreData
/// A composite `Operation` to both download and parse earthquake data. /// A composite `EarthquakeOperation` to both download and parse earthquake data.
class GetEarthquakesOperation: GroupOperation { class GetEarthquakesOperation: GroupOperation {
// MARK: Properties // MARK: Properties

View file

@ -9,7 +9,7 @@ This file contains the code to create the Core Data stack.
import CoreData import CoreData
/** /**
An `Operation` subclass that loads the Core Data stack. If this operation fails, An `EarthquakeOperation` subclass that loads the Core Data stack. If this operation fails,
it will produce an `AlertOperation` that will offer to retry the operation. it will produce an `AlertOperation` that will offer to retry the operation.
*/ */
class LoadModelOperation: EarthquakeOperation { class LoadModelOperation: EarthquakeOperation {

View file

@ -9,7 +9,7 @@ This file contains the code to present more information about an earthquake as a
import Foundation import Foundation
import SafariServices import SafariServices
/// An `Operation` to display an `URL` in an app-modal `SFSafariViewController`. /// An `EarthquakeOperation` to display an `URL` in an app-modal `SFSafariViewController`.
class MoreInformationOperation: EarthquakeOperation { class MoreInformationOperation: EarthquakeOperation {
// MARK: Properties // MARK: Properties

View file

@ -9,10 +9,11 @@ Contains the code to manage the visibility of the network activity indicator
import UIKit import UIKit
/** /**
An `OperationObserver` that will cause the network activity indicator to appear An `EarthquakeOperationObserver` that will cause the network activity
as long as the `Operation` to which it is attached is executing. indicator to appear as long as the `EarthquakeOperation` to which it is
attached is executing.
*/ */
struct NetworkObserver: OperationObserver { struct NetworkObserver: EarthquakeOperationObserver {
// MARK: Initilization // MARK: Initilization
init() { } init() { }

View file

@ -10,9 +10,9 @@ import Foundation
/** /**
The `BlockObserver` is a way to attach arbitrary blocks to significant events The `BlockObserver` is a way to attach arbitrary blocks to significant events
in an `Operation`'s lifecycle. in an `EarthquakeOperation`'s lifecycle.
*/ */
struct BlockObserver: OperationObserver { struct BlockObserver: EarthquakeOperationObserver {
// MARK: Properties // MARK: Properties
private let startHandler: ((EarthquakeOperation) -> Void)? private let startHandler: ((EarthquakeOperation) -> Void)?

View file

@ -50,7 +50,7 @@ struct CalendarCondition: OperationCondition {
private let SharedEventStore = EKEventStore() private let SharedEventStore = EKEventStore()
/** /**
A private `Operation` that will request access to the user's Calendar/Reminders, A private `EarthquakeOperation` that will request access to the user's Calendar/Reminders,
if it has not already been granted. if it has not already been granted.
*/ */
private class CalendarPermissionOperation: EarthquakeOperation { private class CalendarPermissionOperation: EarthquakeOperation {

View file

@ -9,15 +9,15 @@ This file shows how to make an operation that efficiently waits.
import Foundation import Foundation
/** /**
`DelayOperation` is an `Operation` that will simply wait for a given time `DelayOperation` is an `EarthquakeOperation` that will simply wait for a
interval, or until a specific `NSDate`. given time interval, or until a specific `Date`.
It is important to note that this operation does **not** use the `sleep()` It is important to note that this operation does **not** use the `sleep()`
function, since that is inefficient and blocks the thread on which it is called. function, since that is inefficient and blocks the thread on which it is called.
Instead, this operation uses `dispatch_after` to know when the appropriate amount Instead, this operation uses `DispatchQueue.asyncAfter` to know
of time has passed. when the appropriate amount of time has passed.
If the interval is negative, or the `NSDate` is in the past, then this operation If the interval is negative, or the `Date` is in the past, then this operation
immediately finishes. immediately finishes.
*/ */
class DelayOperation: EarthquakeOperation { class DelayOperation: EarthquakeOperation {

View file

@ -3,7 +3,7 @@ Copyright (C) 2015 Apple Inc. All Rights Reserved.
See LICENSE.txt for this samples licensing information See LICENSE.txt for this samples licensing information
Abstract: Abstract:
This code shows how to create a simple subclass of Operation. This code shows how to create a simple subclass of EarthquakeOperation.
*/ */
import Foundation import Foundation

View file

@ -3,13 +3,13 @@ Copyright (C) 2015 Apple Inc. All Rights Reserved.
See LICENSE.txt for this samples licensing information See LICENSE.txt for this samples licensing information
Abstract: Abstract:
This file contains the foundational subclass of NSOperation. This file contains the foundational subclass of Operation.
*/ */
import Foundation import Foundation
/** /**
The subclass of `NSOperation` from which all other operations should be derived. The subclass of `Operation` from which all other operations should be derived.
This class adds both Conditions and Observers, which allow the operation to define This class adds both Conditions and Observers, which allow the operation to define
extended readiness requirements, as well as notify many interested parties extended readiness requirements, as well as notify many interested parties
about interesting operation state changes about interesting operation state changes
@ -29,31 +29,31 @@ class EarthquakeOperation: Operation {
// MARK: State Management // MARK: State Management
fileprivate enum State: Int, Comparable { fileprivate enum State: Int, Comparable {
/// The initial state of an `Operation`. /// The initial state of an `EarthquakeOperation`.
case Initialized case Initialized
/// The `Operation` is ready to begin evaluating conditions. /// The `EarthquakeOperation` is ready to begin evaluating conditions.
case Pending case Pending
/// The `Operation` is evaluating conditions. /// The `EarthquakeOperation` is evaluating conditions.
case EvaluatingConditions case EvaluatingConditions
/** /**
The `Operation`'s conditions have all been satisfied, and it is ready The `EarthquakeOperation`'s conditions have all been satisfied, and it is ready
to execute. to execute.
*/ */
case Ready case Ready
/// The `Operation` is executing. /// The `EarthquakeOperation` is executing.
case Executing case Executing
/** /**
Execution of the `Operation` has finished, but it has not yet notified Execution of the `EarthquakeOperation` has finished, but it has not yet notified
the queue of this. the queue of this.
*/ */
case Finishing case Finishing
/// The `Operation` has finished executing. /// The `EarthquakeOperation` has finished executing.
case Finished case Finished
func canTransitionToState(target: State) -> Bool { func canTransitionToState(target: State) -> Bool {
@ -79,7 +79,7 @@ class EarthquakeOperation: Operation {
} }
/** /**
Indicates that the Operation can now begin to evaluate readiness conditions, Indicates that the EarthquakeOperation can now begin to evaluate readiness conditions,
if appropriate. if appropriate.
*/ */
func willEnqueue() { func willEnqueue() {
@ -194,9 +194,9 @@ class EarthquakeOperation: Operation {
conditions.append(condition) conditions.append(condition)
} }
private(set) var observers = [OperationObserver]() private(set) var observers = [EarthquakeOperationObserver]()
func addObserver(observer: OperationObserver) { func addObserver(observer: EarthquakeOperationObserver) {
assert(state < .Executing, "Cannot modify observers after execution has begun.") assert(state < .Executing, "Cannot modify observers after execution has begun.")
observers.append(observer) observers.append(observer)
@ -211,7 +211,7 @@ class EarthquakeOperation: Operation {
// MARK: Execution and Cancellation // MARK: Execution and Cancellation
override final func start() { override final func start() {
// NSOperation.start() contains important logic that shouldn't be bypassed. // Operation.start() contains important logic that shouldn't be bypassed.
super.start() super.start()
// If the operation has been cancelled, we still need to enter the "Finished" state. // If the operation has been cancelled, we still need to enter the "Finished" state.
@ -238,12 +238,12 @@ class EarthquakeOperation: Operation {
} }
/** /**
`execute()` is the entry point of execution for all `Operation` subclasses. `execute()` is the entry point of execution for all `EarthquakeOperation`
If you subclass `Operation` and wish to customize its execution, you would subclasses. If you subclass `EarthquakeOperation` and wish to customize its
do so by overriding the `execute()` method. execution, you would do so by overriding the `execute()` method.
At some point, your `Operation` subclass must call one of the "finish" At some point, your `EarthquakeOperation` subclass must call one of the
methods defined below; this is how you indicate that your operation has "finish" methods defined below; this is how you indicate that your operation has
finished its execution, and that operations dependent on yours can re-evaluate finished its execution, and that operations dependent on yours can re-evaluate
their readiness state. their readiness state.
*/ */

View file

@ -12,16 +12,16 @@ import Foundation
The protocol that types may implement if they wish to be notified of significant The protocol that types may implement if they wish to be notified of significant
operation lifecycle events. operation lifecycle events.
*/ */
protocol OperationObserver { protocol EarthquakeOperationObserver {
/// Invoked immediately prior to the `Operation`'s `execute()` method. /// Invoked immediately prior to the `EarthquakeOperation`'s `execute()` method.
func operationDidStart(operation: EarthquakeOperation) func operationDidStart(operation: EarthquakeOperation)
/// Invoked when `Operation.produceOperation(_:)` is executed. /// Invoked when `EarthquakeOperation.produceOperation(_:)` is executed.
func operation(operation: EarthquakeOperation, didProduceOperation newOperation: Operation) func operation(operation: EarthquakeOperation, didProduceOperation newOperation: Operation)
/** /**
Invoked as an `Operation` finishes, along with any errors produced during Invoked as an `EarthquakeOperation` finishes, along with any errors produced during
execution (or readiness evaluation). execution (or readiness evaluation).
*/ */
func operationDidFinish(operation: EarthquakeOperation, errors: [NSError]) func operationDidFinish(operation: EarthquakeOperation, errors: [NSError])

View file

@ -3,20 +3,20 @@ Copyright (C) 2015 Apple Inc. All Rights Reserved.
See LICENSE.txt for this samples licensing information See LICENSE.txt for this samples licensing information
Abstract: Abstract:
This file contains an NSOperationQueue subclass. This file contains an OperationQueue subclass.
*/ */
import Foundation import Foundation
/** /**
The delegate of an `OperationQueue` can respond to `Operation` lifecycle The delegate of an `EarthquakeOperationQueue` can respond to `EarthquakeOperation`
events by implementing these methods. lifecycle events by implementing these methods.
In general, implementing `OperationQueueDelegate` is not necessary; you would In general, implementing `EarthquakeOperationQueueDelegate` is not necessary; you would
want to use an `OperationObserver` instead. However, there are a couple of want to use an `EarthquakeOperationObserver` instead. However, there are a couple of
situations where using `OperationQueueDelegate` can lead to simpler code. situations where using `EarthquakeOperationQueueDelegate` can lead to simpler code.
For example, `GroupOperation` is the delegate of its own internal For example, `GroupOperation` is the delegate of its own internal
`OperationQueue` and uses it to manage dependencies. `EarthquakeOperationQueue` and uses it to manage dependencies.
*/ */
@objc protocol EarthquakeOperationQueueDelegate: NSObjectProtocol { @objc protocol EarthquakeOperationQueueDelegate: NSObjectProtocol {
@objc optional func operationQueue(operationQueue: EarthquakeOperationQueue, willAddOperation operation: Operation) @objc optional func operationQueue(operationQueue: EarthquakeOperationQueue, willAddOperation operation: Operation)
@ -24,8 +24,8 @@ import Foundation
} }
/** /**
`OperationQueue` is an `NSOperationQueue` subclass that implements a large `EarthquakeOperationQueue` is an `OperationQueue` subclass that implements a large
number of "extra features" related to the `Operation` class: number of "extra features" related to the `EarthquakeOperation` class:
- Notifying a delegate of all operation completion - Notifying a delegate of all operation completion
- Extracting generated dependencies from operation conditions - Extracting generated dependencies from operation conditions
@ -36,7 +36,7 @@ class EarthquakeOperationQueue: OperationQueue {
override func addOperation(_ operation: Operation) { override func addOperation(_ operation: Operation) {
if let op = operation as? EarthquakeOperation { if let op = operation as? EarthquakeOperation {
// Set up a `BlockObserver` to invoke the `OperationQueueDelegate` method. // Set up a `BlockObserver` to invoke the `EarthquakeOperationQueueDelegate` method.
let delegate = BlockObserver( let delegate = BlockObserver(
startHandler: nil, startHandler: nil,
produceHandler: { [weak self] in produceHandler: { [weak self] in
@ -91,10 +91,10 @@ class EarthquakeOperationQueue: OperationQueue {
} }
else { else {
/* /*
For regular `NSOperation`s, we'll manually call out to the queue's For regular `EarthquakeOperation`s, we'll manually call out to the
delegate we don't want to just capture "operation" because that queue's delegate we don't want to just capture "operation" because
would lead to the operation strongly referencing itself and that's that would lead to the operation strongly referencing itself and
the pure definition of a memory leak. that's the pure definition of a memory leak.
*/ */
operation.addCompletionBlock { [weak self, weak operation] in operation.addCompletionBlock { [weak self, weak operation] in
guard let queue = self, let operation = operation else { return } guard let queue = self, let operation = operation else { return }

View file

@ -10,9 +10,10 @@ import Foundation
/** /**
`ExclusivityController` is a singleton to keep track of all the in-flight `ExclusivityController` is a singleton to keep track of all the in-flight
`Operation` instances that have declared themselves as requiring mutual exclusivity. `EarthquakeOperation` instances that have declared themselves as requiring
We use a singleton because mutual exclusivity must be enforced across the entire mutual exclusivity. We use a singleton because mutual exclusivity must be enforced
app, regardless of the `OperationQueue` on which an `Operation` was executed. across the entire app, regardless of the `EarthquakeOperationQueue` on which an
`EarthquakeOperation` was executed.
*/ */
class ExclusivityController { class ExclusivityController {
static let sharedExclusivityController = ExclusivityController() static let sharedExclusivityController = ExclusivityController()

View file

@ -9,7 +9,7 @@ This file shows how operations can be composed together to form new operations.
import Foundation import Foundation
/** /**
A subclass of `Operation` that executes zero or more operations as part of its A subclass of `EarthquakeOperation` that executes zero or more operations as part of its
own execution. This class of operation is very useful for abstracting several own execution. This class of operation is very useful for abstracting several
smaller operations into a larger operation. As an example, the `GetEarthquakesOperation` smaller operations into a larger operation. As an example, the `GetEarthquakesOperation`
is composed of both a `DownloadEarthquakesOperation` and a `ParseEarthquakesOperation`. is composed of both a `DownloadEarthquakesOperation` and a `ParseEarthquakesOperation`.

View file

@ -12,7 +12,7 @@ import HealthKit
import UIKit import UIKit
/** /**
A condition to indicate an `Operation` requires access to the user's health A condition to indicate an `EarthquakeOperation` requires access to the user's health
data. data.
*/ */
struct HealthCondition: OperationCondition { struct HealthCondition: OperationCondition {
@ -92,7 +92,7 @@ struct HealthCondition: OperationCondition {
} }
/** /**
A private `Operation` that will request access to the user's health data, if A private `EarthquakeOperation` that will request access to the user's health data, if
it has not already been granted. it has not already been granted.
*/ */
private class HealthPermissionOperation: EarthquakeOperation { private class HealthPermissionOperation: EarthquakeOperation {

View file

@ -79,7 +79,7 @@ struct LocationCondition: OperationCondition {
} }
/** /**
A private `Operation` that will request permission to access the user's location, A private `EarthquakeOperation` that will request permission to access the user's location,
if permission has not already been granted. if permission has not already been granted.
*/ */
private class LocationPermissionOperation: EarthquakeOperation { private class LocationPermissionOperation: EarthquakeOperation {

View file

@ -10,10 +10,10 @@ import Foundation
import CoreLocation import CoreLocation
/** /**
`LocationOperation` is an `Operation` subclass to do a "one-shot" request to `LocationOperation` is an `EarthquakeOperation` subclass to do
get the user's current location, with a desired accuracy. This operation will a "one-shot" request to get the user's current location, with a desired accuracy.
prompt for `WhenInUse` location authorization, if the app does not already This operation will prompt for `WhenInUse` location authorization, if the app
have it. does not already have it.
*/ */
class LocationOperation: EarthquakeOperation, CLLocationManagerDelegate { class LocationOperation: EarthquakeOperation, CLLocationManagerDelegate {
// MARK: Properties // MARK: Properties

View file

@ -3,14 +3,14 @@ Copyright (C) 2015 Apple Inc. All Rights Reserved.
See LICENSE.txt for this samples licensing information See LICENSE.txt for this samples licensing information
Abstract: Abstract:
A convenient extension to Foundation.NSOperation. A convenient extension to Foundation.Operation.
*/ */
import Foundation import Foundation
extension Operation { extension Operation {
/** /**
Add a completion block to be executed after the `NSOperation` enters the Add a completion block to be executed after the `Operation` enters the
"finished" state. "finished" state.
*/ */
func addCompletionBlock(block: @escaping () -> Void) { func addCompletionBlock(block: @escaping () -> Void) {

View file

@ -3,7 +3,7 @@ Copyright (C) 2015 Apple Inc. All Rights Reserved.
See LICENSE.txt for this samples licensing information See LICENSE.txt for this samples licensing information
Abstract: Abstract:
This file contains the fundamental logic relating to Operation conditions. This file contains the fundamental logic relating to EarthquakeOperation conditions.
*/ */
import Foundation import Foundation
@ -32,9 +32,9 @@ protocol OperationCondition {
operation is executed first. Use this method to return an operation that operation is executed first. Use this method to return an operation that
(for example) asks for permission to perform the operation (for example) asks for permission to perform the operation
- parameter operation: The `Operation` to which the Condition has been added. - Parameter operation: The `EarthquakeOperation` to which the Condition has been added.
- returns: An `NSOperation`, if a dependency should be automatically added. Otherwise, `nil`. - Returns: An `Operation`, if a dependency should be automatically added. Otherwise, `nil`.
- note: Only a single operation may be returned as a dependency. If you - Note: Only a single operation may be returned as a dependency. If you
find that you need to return multiple operations, then you should be find that you need to return multiple operations, then you should be
expressing that as multiple conditions. Alternatively, you could return expressing that as multiple conditions. Alternatively, you could return
a single `GroupOperation` that executes multiple operations internally. a single `GroupOperation` that executes multiple operations internally.

View file

@ -38,7 +38,7 @@ struct PhotosCondition: OperationCondition {
} }
/** /**
A private `Operation` that will request access to the user's Photos, if it A private `EarthquakeOperation` that will request access to the user's Photos, if it
has not already been granted. has not already been granted.
*/ */
private class PhotosPermissionOperation: EarthquakeOperation { private class PhotosPermissionOperation: EarthquakeOperation {

View file

@ -68,7 +68,7 @@ struct RemoteNotificationCondition: OperationCondition {
} }
/** /**
A private `Operation` to request a push notification token from the `UIApplication`. A private `EarthquakeOperation` to request a push notification token from the `UIApplication`.
- note: This operation is used for *both* the generated dependency **and** - note: This operation is used for *both* the generated dependency **and**
condition evaluation, since there is no "easy" way to retrieve the push condition evaluation, since there is no "easy" way to retrieve the push

View file

@ -9,10 +9,10 @@ This file shows how to implement the OperationObserver protocol.
import Foundation import Foundation
/** /**
`TimeoutObserver` is a way to make an `Operation` automatically time out and `TimeoutObserver` is a way to make an `EarthquakeOperation` automatically time out and
cancel after a specified time interval. cancel after a specified time interval.
*/ */
struct TimeoutObserver: OperationObserver { struct TimeoutObserver {
// MARK: Properties // MARK: Properties
static let timeoutKey = "Timeout" static let timeoutKey = "Timeout"
@ -24,9 +24,11 @@ struct TimeoutObserver: OperationObserver {
init(timeout: Int) { init(timeout: Int) {
self.timeout = timeout self.timeout = timeout
} }
}
// MARK: OperationObserver // MARK: EarthquakeOperationObserver
extension TimeoutObserver: EarthquakeOperationObserver {
func operationDidStart(operation: EarthquakeOperation) { func operationDidStart(operation: EarthquakeOperation) {
// When the operation starts, queue up a block to cause it to time out. // When the operation starts, queue up a block to cause it to time out.
DispatchQueue.global(qos: .default).asyncAfter(deadline: .now() + .seconds(timeout)) { DispatchQueue.global(qos: .default).asyncAfter(deadline: .now() + .seconds(timeout)) {

View file

@ -3,7 +3,7 @@ Copyright (C) 2015 Apple Inc. All Rights Reserved.
See LICENSE.txt for this samples licensing information See LICENSE.txt for this samples licensing information
Abstract: Abstract:
Shows how to lift operation-like objects in to the NSOperation world. Shows how to lift operation-like objects in to the Operation world.
*/ */
import Foundation import Foundation
@ -11,8 +11,8 @@ import Foundation
private var URLSessionTaksOperationKVOContext = 0 private var URLSessionTaksOperationKVOContext = 0
/** /**
`URLSessionTaskOperation` is an `Operation` that lifts an `URLSessionTask` `URLSessionTaskOperation` is an `EarthquakeOperation` that lifts
into an operation. an `URLSessionTask` into an operation.
Note that this operation does not participate in any of the delegate callbacks \ Note that this operation does not participate in any of the delegate callbacks \
of an `URLSession`, but instead uses Key-Value-Observing to know when the of an `URLSession`, but instead uses Key-Value-Observing to know when the

View file

@ -82,7 +82,7 @@ struct UserNotificationCondition: OperationCondition {
} }
/** /**
A private `Operation` subclass to register a `UIUserNotificationSettings` A private `EarthquakeOperation` subclass to register a `UIUserNotificationSettings`
object with a `UIApplication`, prompting the user for permission if necessary. object with a `UIApplication`, prompting the user for permission if necessary.
*/ */
private class UserNotificationPermissionOperation: EarthquakeOperation { private class UserNotificationPermissionOperation: EarthquakeOperation {

View file

@ -58,7 +58,7 @@ private struct ParsedEarthquake {
} }
} }
/// An `Operation` to parse earthquakes out of a downloaded feed from the USGS. /// An `EarthquakeOperation` to parse earthquakes out of a downloaded feed from the USGS.
class ParseEarthquakesOperation: EarthquakeOperation { class ParseEarthquakesOperation: EarthquakeOperation {
let cacheFile: URL let cacheFile: URL
let context: NSManagedObjectContext let context: NSManagedObjectContext