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 <z...@mac.com> 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 (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com