October 2013
Intermediate to advanced
1053 pages
28h 7m
English
You want to run a series of tasks synchronously.
Create operations and start them manually:
@interfaceAppDelegate()@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 this type is to invoke a method in an
object. This is the most straightforward way to invoke a method inside
an object using operations.
An ...
Read now
Unlock full access