class AppDelegate def application(application, didFinishLaunchingWithOptions:launchOptions) @window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds).tap do |win| win.rootViewController = AsyncController.alloc.init win.makeKeyAndVisible end true end end class AsyncController < UIViewController def thread1 10.times { |i| NSLog("\t Thread1: %@", i) } end def thread2 20.times { |i| NSLog("\t\t Thread2: %@", i) } end def thread3 30.times { |i| NSLog("\t\t\t Thread3: %@", i) } end def viewDidLoad self.view.backgroundColor = UIColor.whiteColor @queue = NSOperationQueue.new @queue.maxConcurrentOperationCount = 3 @queue.name = "threads operation" operation1 = NSInvocationOperation.alloc.initWithTarget(self, selector: :thread1, object:nil) operation2 = NSInvocationOperation.alloc.initWithTarget(self, selector: :thread2, object:nil) operation3 = NSInvocationOperation.alloc.initWithTarget(self, selector: :thread3, object:nil) @queue.addOperation(operation1) @queue.addOperation(operation2) @queue.addOperation(operation3) end end