Created
April 8, 2016 08:49
-
-
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.
This file contains hidden or 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
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) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample project based on Advanced NSOperations:
https://dl.dropboxusercontent.com/u/546085/AdvancedNSOperationsCRASH.zip