Skip to content

Commit cd89e45

Browse files
committed
Operation: add willChangeValue() and didChangeValue()
1 parent 42d0cf6 commit cd89e45

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

Foundation/NSOperation.swift

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ open class Operation : NSObject {
4747
#endif
4848
}
4949

50-
/// - Note: Operations that are asynchronous from the execution of the operation queue itself are not supported since there is no KVO to trigger the finish.
5150
open func start() {
5251
main()
5352
finish()
@@ -159,6 +158,24 @@ open class Operation : NSObject {
159158
}
160159
}
161160

161+
/// The following two methods are added to provide support for Operations which
162+
/// are asynchronous from the execution of the operation queue itself. On Darwin,
163+
/// this is supported via KVO notifications. In the absence of KVO on non-Darwin
164+
/// platforms, these two methods (which are defined in NSObject on Darwin) are
165+
/// temporarily added here. They should be removed once a permanent solution is
166+
/// found.
167+
extension Operation {
168+
public func willChangeValue(forKey key: String) {
169+
// do nothing
170+
}
171+
172+
public func didChangeValue(forKey key: String) {
173+
if key == "isFinished" && isFinished {
174+
finish()
175+
}
176+
}
177+
}
178+
162179
extension Operation {
163180
public enum QueuePriority : Int {
164181
case veryLow

0 commit comments

Comments
 (0)