Gikas Gikas - 3 months ago 21
Objective-C Question

What's *__strong* means?

There is a method:

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


What is a __strong in parameters means? Why two asterisks?

Answer

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

__strong is the opposite of __weak which you should already now. 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