3

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?

Proud Member
  • 40,078
  • 47
  • 146
  • 231

2 Answers2

4

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.

BJ Homer
  • 48,806
  • 11
  • 116
  • 129
  • Though it apparently doesn't matter *in this case*, it might be better if you put it in the right place. E.g. a `const T * *` is **NOT** the same as a `T * const *` so why do it wrong for `__autoreleasing` just because the compiler will fix the placement? – CRD Jan 15 '12 at 02:59
  • It's not that the compiler will fix it; it's that in this case they're all equally valid and all mean the same thing. You're right that in the case of `const` it makes a difference. Here, it does not. It's a false analogy. – BJ Homer Jan 15 '12 at 03:35
1

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.

Tim
  • 14,447
  • 6
  • 40
  • 63
  • Hopefully this helps: http://stackoverflow.com/questions/5433935/how-can-i-examine-assembly-in-xcode-4 – Tim Jan 14 '12 at 19:47