How to fix “property’s synthesized getter follows Cocoa naming convention for returning ‘owned’ objects”

- by

Today Xcode surprised me with an error message I hadn’t heard before: property’s synthesized getter follows Cocoa naming convention for returning ‘owned’ objects.

At first I thought, “isn’t that a good thing?”, and after checking how I had defined a new property I was clueless why this was happening:

@property (nonatomic, strong) Phrase *newPhrase;

What I had done was define a new property that starts with “new”. Doing so means that Xcode / ARC does not automatically create the getter/setter methods for me automatically, and expects me to do it (since I own the object outright). Not having done so throws an error message at build time.

To avoid this problem, don’t start properties beginning with

  • new
  • alloc
  • copy
  • mutableCopy

If you must name properties with those prefixes, then you need to create everything Xcode would do for you too. Most of us really don’t know/care what that is so it’s probably easier to just change that property.

You can use things like “new” for objects you create during the course of your methods, just not as properties. The following works just fine:

- (void)myMethod {
    Phrase *newPhrase = @"Merry Christmas";

If you enjoy my content, please consider supporting me on Ko-fi. In return you can browse this whole site without any pesky ads! More details here.

Leave a Comment!

This site uses Akismet to reduce spam. Learn how your comment data is processed.