Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does double pointer mean in Objective-C? [duplicate]

I begin to learn an Objective-C after 5 years of experience in Java and don't understand some of it's constructions. What does this Some_Object** mean? For example in the method definition here:

- (NSString *)checkLastUpdate:(NSUInteger)loggedId   
 returnMsgs:(NSMutableArray **)returnMsgs
 {
       ....
if (returnMsgs) 
 {
*returnMsgs = NewMsgs;
}
     }

It is pointer to pointer or what? And what it is the reason of using this?

like image 790
MainstreamDeveloper00 Avatar asked Feb 18 '23 09:02

MainstreamDeveloper00


1 Answers

It's Pointer-to-pointer type, the same thing in C language.

I don't think it is a good behavior except for error callback. For example, we call one function and need error info in case that the function failed:

- (id)handleData:(NSData *)inData error:(NSError **)outError;
{
if (inData == NULL || [inData length] == 0)
    {
    if (outError)
        *outError = [NSError errorWithDomain:kDataErrorDomain code:-1 userInfo:NULL];

We can call like this :

NSError *error = NULL;
[self handleData:data error:&error];

if (error) {
    // Handle error
like image 146
Jason Lee Avatar answered Feb 20 '23 01:02

Jason Lee