title: How to create an NSInvocation object using a method that takes a pointer to an object as an argument
body: <p>I would like to create an NSInvocation object using a method that takes a pointer to an NSError object as an argument. An example of this would be the method -</p>
  
  <pre><code>- (BOOL)writeToFile:(NSString *)path options:(NSDataWritingOptions)mask error:(NSError **)errorPtr
  </code></pre>
  
  <p>I undersand that I would set my invocation up like this</p>
  
  <pre><code>NSData *myData = [[NSData alloc] init];
  
  SEL writeToFileSelector = @selector(writeToFile:options:error:);
  NSMethodSignature *signature = [NSData instanceMethodSignatureForSelector:writeToFileSelector];
  
  NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
  [invocation setTarget:myData];
  [invocation setSelector:writeToFileSelector];
  
  NSString *string = [NSString stringWithFormat:@"long cat"];
  NSDataWritingOptions *dataOptions;
  *dataOptions = NSDataWritingFileProtectionComplete;
  
  [invocation setArgument:&amp;string atIndex:2];
  [invocation setArgument:&amp;dataOptions atIndex:3];
  </code></pre>
  
  <p>For writeToFile:Options:Error: the last argument is expecting to receive a pointer instead of an object. As a result doing the following does not work - </p>
  
  <pre><code>NSError *err = nil;
  [invocation setArgument:&amp;err atIndex:4];
  </code></pre>
  
  <p>It seems logical that the solution might be to create a pointer to a pointer, but this causes a compiler warning. I am not sure how to execute that properly and not create a memory management problem.</p>