• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Reserved method prefixes in Cocoa. Is there a reference list?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Reserved method prefixes in Cocoa. Is there a reference list?


  • Subject: Re: Reserved method prefixes in Cocoa. Is there a reference list?
  • From: Alex Zavatone <email@hidden>
  • Date: Wed, 29 May 2013 15:06:25 -0400

Now that my brain cell's caffeine levels are normalizing, I seem to recall somewhere in the Cocoa docs stating that starting a method name with a string like "return" is somewhat frowned upon.

Yeah, it must have been in the ARC docs.  I remember that using init or new are not good ideas.

That pointed me in the right direction:

Here's part of what I was concerned about from:
https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/MemoryMgmt/MemoryMgmt.pdf

Basic Memory Management Rules
The memory management model is based on object ownership. Any object may have one or more owners. As long as an object has at least one owner, it continues to exist. If an object has no owners, the runtime system destroys it automatically. To make sure it is clear when you own an object and when you do not, Cocoa sets the following policy:

•	You own any object you create
	You create an object using a method whose name begins with “alloc”, “new”, “copy”, or “mutableCopy” (for example, alloc, newObject, or mutableCopy).


I'll just try to note any rules or recommendations that I come across.  Thanks.

On May 29, 2013, at 2:28 PM, Jens Alfke wrote:

>
> On May 29, 2013, at 10:37 AM, Alex Zavatone <email@hidden> wrote:
>
>> I'm aware that certain prefixes like "set" are bad news to use to start method names for obvious reasons, but with the caffeine levels in my brain cell running low, I'm at a loss to recall some of the others (is return verboten?).  Is there a list of reserved method prefix strings that you simply shouldn't use to start your methods?
>
> There aren’t any forbidden prefixes that I know of, but there are ones that should be used only for particular purposes, because the compiler and/or runtime will make assumptions about them when they see that prefix.
>
> It’s fine to have a method -setFoo:, it’s just that it will be interpreted as a setter for a property “foo”. Which is usually what you meant anyway.
>
> ARC makes assumptions about special refcounting behavior of methods named “copy” or “mutableCopy” or that start with “init” or “alloc” or “new” — all of these are assumed to return an object reference that needs to be released by the caller. There might be others but those are all I can remember; the ARC docs may have a complete list.
>
> —Jens

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


References: 
 >Reserved method prefixes in Cocoa. Is there a reference list? (From: Alex Zavatone <email@hidden>)
 >Re: Reserved method prefixes in Cocoa. Is there a reference list? (From: Jens Alfke <email@hidden>)

  • Prev by Date: Re: Flash inside an app
  • Next by Date: Re: Reserved method prefixes in Cocoa. Is there a reference list?
  • Previous by thread: Re: Reserved method prefixes in Cocoa. Is there a reference list?
  • Next by thread: Re: Reserved method prefixes in Cocoa. Is there a reference list?
  • Index(es):
    • Date
    • Thread