mirror of
https://github.com/samsonjs/Advanced-NSOperations.git
synced 2026-03-25 08:25:47 +00:00
Update type names and comments
This commit is contained in:
parent
77f9ae6860
commit
1b4ded021d
27 changed files with 96 additions and 92 deletions
|
|
@ -19,13 +19,13 @@
|
|||
553F50161B08E98A005F991E /* LoadModelOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 553F50151B08E98A005F991E /* LoadModelOperation.swift */; };
|
||||
55817C3A1B18FDF8001C0CE2 /* EarthquakeOperationQueue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 551B9C061AEB2D7800302388 /* EarthquakeOperationQueue.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 */; };
|
||||
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 */; };
|
||||
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 */; };
|
||||
55817C441B18FDF8001C0CE2 /* TimeoutObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55AD643C1B128CC3000EF5CB /* TimeoutObserver.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>"; };
|
||||
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>"; };
|
||||
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>"; };
|
||||
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>"; };
|
||||
|
|
@ -227,7 +227,7 @@
|
|||
553F50071B0817BB005F991E /* Observers */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
553F50051B081760005F991E /* OperationObserver.swift */,
|
||||
553F50051B081760005F991E /* EarthquakeOperationObserver.swift */,
|
||||
553F50081B0817D2005F991E /* BlockObserver.swift */,
|
||||
55AD643C1B128CC3000EF5CB /* TimeoutObserver.swift */,
|
||||
);
|
||||
|
|
@ -417,7 +417,7 @@
|
|||
55817C3E1B18FDF8001C0CE2 /* GroupOperation.swift in Sources */,
|
||||
55817C491B18FDF8001C0CE2 /* NoCancelledDependencies.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 */,
|
||||
553F500F1B081A9D005F991E /* NetworkObserver.swift in Sources */,
|
||||
55817C551B18FDF8001C0CE2 /* Dictionary+Operations.swift in Sources */,
|
||||
|
|
|
|||
|
|
@ -9,13 +9,13 @@ Contains the code related to automatic background tasks
|
|||
import UIKit
|
||||
|
||||
/**
|
||||
`BackgroundObserver` is an `OperationObserver` that will automatically begin
|
||||
and end a background task if the application transitions to the background.
|
||||
This would be useful if you had a vital `Operation` whose execution *must* complete,
|
||||
regardless of the activation state of the app. Some kinds network connections
|
||||
may fall in to this category, for example.
|
||||
`BackgroundObserver` is an `EarthquakeOperationObserver` that will
|
||||
automatically begin and end a background task if the application transitions to the
|
||||
background. This would be useful if you had a vital `EarthquakeOperation`
|
||||
whose execution *must* complete, regardless of the activation state of the app.
|
||||
Some kinds network connections may fall in to this category, for example.
|
||||
*/
|
||||
class BackgroundObserver: NSObject, OperationObserver {
|
||||
class BackgroundObserver: NSObject, EarthquakeOperationObserver {
|
||||
// MARK: Properties
|
||||
|
||||
private var identifier = UIBackgroundTaskIdentifier.invalid
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ class EarthquakeTableViewController: UITableViewController {
|
|||
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
let shareOperation = EarthquakeBlockOperation { (continuation: @escaping () -> Void) in
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ This file sets up the operations to download and parse earthquake data. It will
|
|||
|
||||
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 {
|
||||
// MARK: Properties
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ This file contains the code to create the Core Data stack.
|
|||
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.
|
||||
*/
|
||||
class LoadModelOperation: EarthquakeOperation {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ This file contains the code to present more information about an earthquake as a
|
|||
import Foundation
|
||||
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 {
|
||||
// MARK: Properties
|
||||
|
||||
|
|
|
|||
|
|
@ -9,10 +9,11 @@ Contains the code to manage the visibility of the network activity indicator
|
|||
import UIKit
|
||||
|
||||
/**
|
||||
An `OperationObserver` that will cause the network activity indicator to appear
|
||||
as long as the `Operation` to which it is attached is executing.
|
||||
An `EarthquakeOperationObserver` that will cause the network activity
|
||||
indicator to appear as long as the `EarthquakeOperation` to which it is
|
||||
attached is executing.
|
||||
*/
|
||||
struct NetworkObserver: OperationObserver {
|
||||
struct NetworkObserver: EarthquakeOperationObserver {
|
||||
// MARK: Initilization
|
||||
|
||||
init() { }
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@ import Foundation
|
|||
|
||||
/**
|
||||
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
|
||||
|
||||
private let startHandler: ((EarthquakeOperation) -> Void)?
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ struct CalendarCondition: OperationCondition {
|
|||
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.
|
||||
*/
|
||||
private class CalendarPermissionOperation: EarthquakeOperation {
|
||||
|
|
|
|||
|
|
@ -9,15 +9,15 @@ This file shows how to make an operation that efficiently waits.
|
|||
import Foundation
|
||||
|
||||
/**
|
||||
`DelayOperation` is an `Operation` that will simply wait for a given time
|
||||
interval, or until a specific `NSDate`.
|
||||
`DelayOperation` is an `EarthquakeOperation` that will simply wait for a
|
||||
given time interval, or until a specific `Date`.
|
||||
|
||||
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.
|
||||
Instead, this operation uses `dispatch_after` to know when the appropriate amount
|
||||
of time has passed.
|
||||
Instead, this operation uses `DispatchQueue.asyncAfter` to know
|
||||
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.
|
||||
*/
|
||||
class DelayOperation: EarthquakeOperation {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ Copyright (C) 2015 Apple Inc. All Rights Reserved.
|
|||
See LICENSE.txt for this sample’s licensing information
|
||||
|
||||
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
|
||||
|
|
|
|||
|
|
@ -3,13 +3,13 @@ Copyright (C) 2015 Apple Inc. All Rights Reserved.
|
|||
See LICENSE.txt for this sample’s licensing information
|
||||
|
||||
Abstract:
|
||||
This file contains the foundational subclass of NSOperation.
|
||||
This file contains the foundational subclass of Operation.
|
||||
*/
|
||||
|
||||
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
|
||||
extended readiness requirements, as well as notify many interested parties
|
||||
about interesting operation state changes
|
||||
|
|
@ -29,31 +29,31 @@ class EarthquakeOperation: Operation {
|
|||
// MARK: State Management
|
||||
|
||||
fileprivate enum State: Int, Comparable {
|
||||
/// The initial state of an `Operation`.
|
||||
/// The initial state of an `EarthquakeOperation`.
|
||||
case Initialized
|
||||
|
||||
/// The `Operation` is ready to begin evaluating conditions.
|
||||
/// The `EarthquakeOperation` is ready to begin evaluating conditions.
|
||||
case Pending
|
||||
|
||||
/// The `Operation` is evaluating conditions.
|
||||
/// The `EarthquakeOperation` is evaluating conditions.
|
||||
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.
|
||||
*/
|
||||
case Ready
|
||||
|
||||
/// The `Operation` is executing.
|
||||
/// The `EarthquakeOperation` is 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.
|
||||
*/
|
||||
case Finishing
|
||||
|
||||
/// The `Operation` has finished executing.
|
||||
/// The `EarthquakeOperation` has finished executing.
|
||||
case Finished
|
||||
|
||||
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.
|
||||
*/
|
||||
func willEnqueue() {
|
||||
|
|
@ -194,9 +194,9 @@ class EarthquakeOperation: Operation {
|
|||
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.")
|
||||
|
||||
observers.append(observer)
|
||||
|
|
@ -211,7 +211,7 @@ class EarthquakeOperation: Operation {
|
|||
// MARK: Execution and Cancellation
|
||||
|
||||
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()
|
||||
|
||||
// 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.
|
||||
If you subclass `Operation` and wish to customize its execution, you would
|
||||
do so by overriding the `execute()` method.
|
||||
`execute()` is the entry point of execution for all `EarthquakeOperation`
|
||||
subclasses. If you subclass `EarthquakeOperation` and wish to customize its
|
||||
execution, you would do so by overriding the `execute()` method.
|
||||
|
||||
At some point, your `Operation` subclass must call one of the "finish"
|
||||
methods defined below; this is how you indicate that your operation has
|
||||
At some point, your `EarthquakeOperation` subclass must call one of the
|
||||
"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
|
||||
their readiness state.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -12,16 +12,16 @@ import Foundation
|
|||
The protocol that types may implement if they wish to be notified of significant
|
||||
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)
|
||||
|
||||
/// Invoked when `Operation.produceOperation(_:)` is executed.
|
||||
/// Invoked when `EarthquakeOperation.produceOperation(_:)` is executed.
|
||||
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).
|
||||
*/
|
||||
func operationDidFinish(operation: EarthquakeOperation, errors: [NSError])
|
||||
|
|
@ -3,20 +3,20 @@ Copyright (C) 2015 Apple Inc. All Rights Reserved.
|
|||
See LICENSE.txt for this sample’s licensing information
|
||||
|
||||
Abstract:
|
||||
This file contains an NSOperationQueue subclass.
|
||||
This file contains an OperationQueue subclass.
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
|
||||
/**
|
||||
The delegate of an `OperationQueue` can respond to `Operation` lifecycle
|
||||
events by implementing these methods.
|
||||
The delegate of an `EarthquakeOperationQueue` can respond to `EarthquakeOperation`
|
||||
lifecycle events by implementing these methods.
|
||||
|
||||
In general, implementing `OperationQueueDelegate` is not necessary; you would
|
||||
want to use an `OperationObserver` instead. However, there are a couple of
|
||||
situations where using `OperationQueueDelegate` can lead to simpler code.
|
||||
In general, implementing `EarthquakeOperationQueueDelegate` is not necessary; you would
|
||||
want to use an `EarthquakeOperationObserver` instead. However, there are a couple of
|
||||
situations where using `EarthquakeOperationQueueDelegate` can lead to simpler code.
|
||||
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 optional func operationQueue(operationQueue: EarthquakeOperationQueue, willAddOperation operation: Operation)
|
||||
|
|
@ -24,8 +24,8 @@ import Foundation
|
|||
}
|
||||
|
||||
/**
|
||||
`OperationQueue` is an `NSOperationQueue` subclass that implements a large
|
||||
number of "extra features" related to the `Operation` class:
|
||||
`EarthquakeOperationQueue` is an `OperationQueue` subclass that implements a large
|
||||
number of "extra features" related to the `EarthquakeOperation` class:
|
||||
|
||||
- Notifying a delegate of all operation completion
|
||||
- Extracting generated dependencies from operation conditions
|
||||
|
|
@ -36,7 +36,7 @@ class EarthquakeOperationQueue: OperationQueue {
|
|||
|
||||
override func addOperation(_ operation: Operation) {
|
||||
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(
|
||||
startHandler: nil,
|
||||
produceHandler: { [weak self] in
|
||||
|
|
@ -91,10 +91,10 @@ class EarthquakeOperationQueue: OperationQueue {
|
|||
}
|
||||
else {
|
||||
/*
|
||||
For regular `NSOperation`s, we'll manually call out to the queue's
|
||||
delegate we don't want to just capture "operation" because that
|
||||
would lead to the operation strongly referencing itself and that's
|
||||
the pure definition of a memory leak.
|
||||
For regular `EarthquakeOperation`s, we'll manually call out to the
|
||||
queue's delegate we don't want to just capture "operation" because
|
||||
that would lead to the operation strongly referencing itself and
|
||||
that's the pure definition of a memory leak.
|
||||
*/
|
||||
operation.addCompletionBlock { [weak self, weak operation] in
|
||||
guard let queue = self, let operation = operation else { return }
|
||||
|
|
|
|||
|
|
@ -10,9 +10,10 @@ import Foundation
|
|||
|
||||
/**
|
||||
`ExclusivityController` is a singleton to keep track of all the in-flight
|
||||
`Operation` instances that have declared themselves as requiring mutual exclusivity.
|
||||
We use a singleton because mutual exclusivity must be enforced across the entire
|
||||
app, regardless of the `OperationQueue` on which an `Operation` was executed.
|
||||
`EarthquakeOperation` instances that have declared themselves as requiring
|
||||
mutual exclusivity. We use a singleton because mutual exclusivity must be enforced
|
||||
across the entire app, regardless of the `EarthquakeOperationQueue` on which an
|
||||
`EarthquakeOperation` was executed.
|
||||
*/
|
||||
class ExclusivityController {
|
||||
static let sharedExclusivityController = ExclusivityController()
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ This file shows how operations can be composed together to form new operations.
|
|||
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
|
||||
smaller operations into a larger operation. As an example, the `GetEarthquakesOperation`
|
||||
is composed of both a `DownloadEarthquakesOperation` and a `ParseEarthquakesOperation`.
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import HealthKit
|
|||
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.
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
private class HealthPermissionOperation: EarthquakeOperation {
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
*/
|
||||
private class LocationPermissionOperation: EarthquakeOperation {
|
||||
|
|
|
|||
|
|
@ -10,10 +10,10 @@ import Foundation
|
|||
import CoreLocation
|
||||
|
||||
/**
|
||||
`LocationOperation` is an `Operation` subclass to do a "one-shot" request to
|
||||
get the user's current location, with a desired accuracy. This operation will
|
||||
prompt for `WhenInUse` location authorization, if the app does not already
|
||||
have it.
|
||||
`LocationOperation` is an `EarthquakeOperation` subclass to do
|
||||
a "one-shot" request to get the user's current location, with a desired accuracy.
|
||||
This operation will prompt for `WhenInUse` location authorization, if the app
|
||||
does not already have it.
|
||||
*/
|
||||
class LocationOperation: EarthquakeOperation, CLLocationManagerDelegate {
|
||||
// MARK: Properties
|
||||
|
|
|
|||
|
|
@ -3,14 +3,14 @@ Copyright (C) 2015 Apple Inc. All Rights Reserved.
|
|||
See LICENSE.txt for this sample’s licensing information
|
||||
|
||||
Abstract:
|
||||
A convenient extension to Foundation.NSOperation.
|
||||
A convenient extension to Foundation.Operation.
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
|
||||
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.
|
||||
*/
|
||||
func addCompletionBlock(block: @escaping () -> Void) {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ Copyright (C) 2015 Apple Inc. All Rights Reserved.
|
|||
See LICENSE.txt for this sample’s licensing information
|
||||
|
||||
Abstract:
|
||||
This file contains the fundamental logic relating to Operation conditions.
|
||||
This file contains the fundamental logic relating to EarthquakeOperation conditions.
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
|
|
@ -32,9 +32,9 @@ protocol OperationCondition {
|
|||
operation is executed first. Use this method to return an operation that
|
||||
(for example) asks for permission to perform the operation
|
||||
|
||||
- parameter operation: The `Operation` to which the Condition has been added.
|
||||
- returns: An `NSOperation`, if a dependency should be automatically added. Otherwise, `nil`.
|
||||
- note: Only a single operation may be returned as a dependency. If you
|
||||
- Parameter operation: The `EarthquakeOperation` to which the Condition has been added.
|
||||
- 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
|
||||
find that you need to return multiple operations, then you should be
|
||||
expressing that as multiple conditions. Alternatively, you could return
|
||||
a single `GroupOperation` that executes multiple operations internally.
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
*/
|
||||
private class PhotosPermissionOperation: EarthquakeOperation {
|
||||
|
|
|
|||
|
|
@ -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**
|
||||
condition evaluation, since there is no "easy" way to retrieve the push
|
||||
|
|
|
|||
|
|
@ -9,10 +9,10 @@ This file shows how to implement the OperationObserver protocol.
|
|||
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.
|
||||
*/
|
||||
struct TimeoutObserver: OperationObserver {
|
||||
struct TimeoutObserver {
|
||||
// MARK: Properties
|
||||
|
||||
static let timeoutKey = "Timeout"
|
||||
|
|
@ -24,9 +24,11 @@ struct TimeoutObserver: OperationObserver {
|
|||
init(timeout: Int) {
|
||||
self.timeout = timeout
|
||||
}
|
||||
|
||||
// MARK: OperationObserver
|
||||
|
||||
}
|
||||
|
||||
// MARK: EarthquakeOperationObserver
|
||||
|
||||
extension TimeoutObserver: EarthquakeOperationObserver {
|
||||
func operationDidStart(operation: EarthquakeOperation) {
|
||||
// When the operation starts, queue up a block to cause it to time out.
|
||||
DispatchQueue.global(qos: .default).asyncAfter(deadline: .now() + .seconds(timeout)) {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ Copyright (C) 2015 Apple Inc. All Rights Reserved.
|
|||
See LICENSE.txt for this sample’s licensing information
|
||||
|
||||
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
|
||||
|
|
@ -11,8 +11,8 @@ import Foundation
|
|||
private var URLSessionTaksOperationKVOContext = 0
|
||||
|
||||
/**
|
||||
`URLSessionTaskOperation` is an `Operation` that lifts an `URLSessionTask`
|
||||
into an operation.
|
||||
`URLSessionTaskOperation` is an `EarthquakeOperation` that lifts
|
||||
an `URLSessionTask` into an operation.
|
||||
|
||||
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
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
*/
|
||||
private class UserNotificationPermissionOperation: EarthquakeOperation {
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
let cacheFile: URL
|
||||
let context: NSManagedObjectContext
|
||||
|
|
|
|||
Loading…
Reference in a new issue