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

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:

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:

About Jay Versluis

Jay is a medical miracle known as Super Survivor. He runs two YouTube channels, five websites and several podcast feeds. To see what else he's up to, and to support him on his mission to make the world a better place, check out his Patreon Campaign.

Leave a Reply

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