Proud Member
Proud Member

Reputation: 40506

Does the position of the ARC ownership qualifier matter?

Apple tends to give examples like this:

NSError __strong *error = nil;

or

-(BOOL)performOperationWithError:(NSError * __autoreleasing *)error;

I'd find it much more readable and logical if I could do it this way:

__strong NSError *error = nil;


-(BOOL)performOperationWithError:(__autoreleasing NSError**)error;

A quick test revealed that the compiler is not complaining about my way of writing it. Am I doing it wrong anyways, or is it just fine to write it like this?

Upvotes: 3

Views: 317

Answers (2)

BJ Homer
BJ Homer

Reputation: 49054

No, the position of the ownership qualifier doesn't matter at all. Since the ownership qualifiers only have meaning for pointer-to-object types, your intention is never ambiguous. The compiler can easily figure out what your intention is no matter where you place it, so ARC does exactly that.

If you have access to the iOS Apple Developer Forums, then you can see where I asked this same question of Apple's engineers at https://devforums.apple.com/message/458606.

Upvotes: 4

Tim
Tim

Reputation: 14446

If the compiler doesn't complain, and you don't get any new leaks because of it, then it's good. You could also compare your assembly outputs from one way vs the other and see if there's any differences (use a diff tool, not TextEdit, or you'll be at it all night :P)

If the asm or binaries are the same, then the compiler's treating it exactly the same. You could also test with Instruments before and after and see if there's any leakages, to make sure it's still handling memory correctly.

Upvotes: 1

Related Questions