Skip to content

Instantly share code, notes, and snippets.

@pronebird
Created April 8, 2016 08:49
Show Gist options
  • Save pronebird/6ccf4e67030f5fdffe65c941c736181c to your computer and use it in GitHub Desktop.
Save pronebird/6ccf4e67030f5fdffe65c941c736181c to your computer and use it in GitHub Desktop.
Reproducing issue in Earthquakes app when one of operations does not transition from .Ready to .Executing state.
import UIKit
let sharedQueue = OperationQueue()
class TestOperation : Operation
{
override func execute() {
dispatch_async(dispatch_get_main_queue()) {
// print("Finished.")
self.finish()
}
}
}
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
// MARK: Properties
var window: UIWindow?
func applicationDidFinishLaunching(application: UIApplication) {
cycle(1)
}
func cycle(take: Int)
{
var operations = [Operation]()
let startOp = BlockOperation {
print("Begin operations: Take \(take)")
}
let endOp = BlockOperation { [weak self] in
print("End operations")
if take < 10 {
self?.cycle(take + 1)
}
else {
print("This is it!")
}
}
for _ in 1...40
{
let op = TestOperation()
op.addDependency(startOp)
endOp.addDependency(op)
operations.append(op)
}
operations.append(startOp)
operations.append(endOp)
sharedQueue.addOperations(operations, waitUntilFinished: false)
}
// MARK: UIApplicationDelegate
func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {
RemoteNotificationCondition.didFailToRegister(error)
}
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
RemoteNotificationCondition.didReceiveNotificationToken(deviceToken)
}
}
@pronebird
Copy link
Author

Sample project based on Advanced NSOperations:

https://dl.dropboxusercontent.com/u/546085/AdvancedNSOperationsCRASH.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment