December 2012
Intermediate to advanced
834 pages
27h
English
You want to run a series of tasks synchronously.
Create operations and start them manually:
#import <UIKit/UIKit.h>@interfaceRunning_Tasks_Synchronously_with_OperationsAppDelegate:UIResponder<UIApplicationDelegate>@property(strong,nonatomic)UIWindow*window;@property(nonatomic,strong)NSInvocationOperation*simpleOperation;@end
The implementation of the application delegate is as follows:
-(void)simpleOperationEntry:(id)paramObject{NSLog(@"Parameter Object = %@",paramObject);NSLog(@"Main Thread = %@",[NSThreadmainThread]);NSLog(@"Current Thread = %@",[NSThreadcurrentThread]);}-(BOOL)application:(UIApplication*)applicationdidFinishLaunchingWithOptions:(NSDictionary*)launchOptions{NSNumber*simpleObject=[NSNumbernumberWithInteger:123];self.simpleOperation=[[NSInvocationOperationalloc]initWithTarget:selfselector:@selector(simpleOperationEntry:)object:simpleObject];[self.simpleOperationstart];self.window=[[UIWindowalloc]initWithFrame:[[UIScreenmainScreen]bounds]];self.window.backgroundColor=[UIColorwhiteColor];[self.windowmakeKeyAndVisible];returnYES;}
The output of this program (in the console window) will be similar to this:
Parameter Object = 123
Main Thread = <NSThread: 0x6810280>{name = (null), num = 1}
Current Thread = <NSThread: 0x6810280>{name = (null), num = 1}As the name of this class implies (NSInvocationOperation), the main responsibility of an object of ...
Read now
Unlock full access