tags:

views:

51

answers:

1

Usign the NSString class method stringWithContentsOfFile:encoding:error I can:

NSError *error;
NSString *fileContent = [NSString stringWithContentsOfFile:... encoding:... error:&error]
if (fileContent == nil) {
  NSLog(@"%@", error);
}

I would like to do something similar along the lines of:

NSString *message;
BOOL result =  [self checkSomeRandomStuff:&message];
if (result == NO) {
  NSLog(@"%@", message);
}

How would I assign the message variable in the method checkSomeRandomStuff?

+4  A: 

Add another * to the parameter type

-(BOOL)checkSomeRandomStuff:(NSString**)message {
  // check some random stuff
  if (something) {
    *message = @"something";
    return YES;
  } else {
    *message = @"some other thing";
    return NO;
  }
}
Zydeco