There is a strong convention in Cocoa programming that methods like this should return an autoreleased object, and the caller should retain it if they want to keep it.
If you want to return a retained object, have the name begin with "new".
In fact, the LLVM compiler uses this naming convention when it does code analysis. It expects methods to return autoreleased objects unless their names begins with new, alloc, copy, or mutableCopy. Methods who's names DO start with new, alloc, copy, or mutableCopy are expected to return retained object.
This is a really, really good idea to follow. When you follow that rule, it's obvious what you need to do with any given object.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
There is a strong convention in Cocoa programming that methods like this should return an autoreleased object, and the caller should retain it if they want to keep it.
If you want to return a retained object, have the name begin with "new".
In fact, the LLVM compiler uses this naming convention when it does code analysis. It expects methods to return autoreleased objects unless their names begins with new, alloc, copy, or mutableCopy. Methods who's names DO start with new, alloc, copy, or mutableCopy are expected to return retained object.
This is a really, really good idea to follow. When you follow that rule, it's obvious what you need to do with any given object.
Thanks, that's exactly what I want to do. Return a retained object, but not an autorelease object.
Hopefully, returning a retained object does not automatically make it an autorelease object
behind the scenes?
I replaced:
Code:
getArray
with:
Code:
newArray
And the compiler warning message went away. I didn't know that was possible.