Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "*__strong*" mean?

Tags:

objective-c

There is a method:

- (void)doSmth:(NSString *__strong*)str {
    NSLog(@"%@", *str);
}

What does it mean when __strong follows the class of a method parameter? Why are there two asterisks?

like image 261
Gikas Avatar asked Feb 06 '23 08:02

Gikas


1 Answers

Two asterisks mean it's a pointer to a pointer.

__strong is the opposite of __weak which you probably already know. It means we are talking about a strong reference here. While we hold to that reference, the object won't be deallocated.

Also we need to know that writing __strong Type *varName is technically wrong (although it works and almost everybody uses it). The correct syntax is Type * __strong varName.

Your syntax is a pointer to a strong reference to NSString. It means that when an object is returned from the method, there must be a release call from ARC to properly deallocate that object.

Please see the related question: NSError and __autoreleasing and the official documentation: Transitioning to ARC

like image 89
Sulthan Avatar answered Feb 13 '23 06:02

Sulthan