I am developing an API that returns an NSData to the caller. I need the object to be provided in the function parameters (not as a return value). Which of the approach below is preferred and why?
NSData* data;
[self foo1:&data];
-(BOOL)foo1:(NSData**)data {
*data = [@"1234" dataUsingEncoding:NSUTF8StringEncoding];
...
}
or
NSMutableData* data = [[NSMutableData alloc] init];
[self foo2:data];
-(BOOL)foo2:(NSMutableData*)data {
[data setData:[@"1234" dataUsingEncoding:NSUTF8StringEncoding]];
}
Thanks @Willeke. I am going to adopt your advice - Use NSMutableData* if the method adds data, use NSData** if the method creates the data.