I am trying to create NSInvocationOperation so that it should call object's method with params
- (void) getImages: (NSRange) bounds
{
NSOperationQueue *queue = [NSOperationQueue new];
NSArray * params = [NSArray arrayWithObjects:
[[NSNumber alloc] initWithInt: bounds.location],
[[NSNumber alloc] initWithInt: bounds.length]];
NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self
selector:@selector(loadImagesWithOperation)
object:params];
[queue addOperation:operation];
[operation release];
}
- (void) loadImagesWithOperation:(NSArray*)bounds {
NSLog(@"loadImagesWithOperation");
}
This code crashes with EXC_BAD_ACCESS. If I change definition of function to be called to this
- (void) loadImagesWithOperation {
NSLog(@"loadImagesWithOperation");
}
everything becomes fine. I have tried to use different syntax in @selector's code block like @selector(loadImagesWithOperation:) and @selector(loadImagesWithOperation:bounds:), but had not succeeded.
What is the right way to define selector and function with params?
Thanks.