On Jul 5, 2009, at 1:40 PM, DKJ wrote:
I'm trying to write one of those convenient class initialisers for
one of my objects. On my still-incomplete understanding of these
matters, this is what I need to have:
Header:
+ (MyObject *)myObject;
Implementation:
+ (MyObject *)myObject
{
My mistake haha.
I guess you learn something new everyday.
On Jul 5, 2009, at 10:55 AM, Chris Hanson wrote:
You absolutely can (and should!) send +alloc to self in a class
method like this. In a class method, "self" represents the class,
not an instance of the class.
This is one reason it
On Jul 5, 2009, at 12:40 PM, DKJ wrote:
I'm trying to write one of those convenient class initialisers for
one of my objects. On my still-incomplete understanding of these
matters, this is what I need to have:
Header:
+ (MyObject *)myObject;
Implementation:
+ (MyObject *)myObject
{
You absolutely can (and should!) send +alloc to self in a class method
like this. In a class method, "self" represents the class, not an
instance of the class.
This is one reason it's important not to refer to class methods as
"static methods," as less dynamic languages do. In Objective-C,
You can't tell 'self' to be allocated. Try this instead:
+ (MyObject *)myObject
{
return [[[MyObject alloc] init] autorelease];
}
On Jul 5, 2009, at 10:40 AM, DKJ wrote:
I'm trying to write one of those convenient class initialisers for
one of my objects. On my still-incomplete un