Last active
June 2, 2017 19:38
-
-
Save bjhomer/e866a405c425e83c8cad53a8ee8f055e to your computer and use it in GitHub Desktop.
Proof that NSOperation.completionBlock is not being cleared.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Run this in an iOS playground. It works correctly on Mac. | |
import Foundation | |
import PlaygroundSupport | |
let page = PlaygroundPage.current | |
page.needsIndefiniteExecution = true | |
func test() { | |
let op = Operation() | |
op.completionBlock = { | |
print(op.completionBlock) // prints "Optional((Function))" | |
DispatchQueue.main.asyncAfter(deadline: .now() + 1, execute: { | |
print(op.completionBlock) // prints "Optional((Function))" | |
op.completionBlock = nil | |
print(op.completionBlock) // prints "nil" | |
page.finishExecution() | |
}) | |
} | |
op.start() | |
} | |
test() | |
// On macOS, these all print `nil`, as expected |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Reported this as rdar://32541724 - http://openradar.appspot.com/32541724
https://github.com/PSPDFKit-labs/radar.apple.com/tree/master/32541724%20-%20CompletionBlockClearingForNSOperation