I\'m reading through Mark Dalrymple\'s Learn Objective-C on the Mac (only at the chapter on Protocols, so still relatively newbish) and trying to figure something out:<
Generally, within a class method, you do use [[self alloc] init]
. For example, the canonical way to write a convenience method for a class is:
+ (id)fooWithBar:(Bar *)aBar
{
return [[[self alloc] initWithBar:aBar] autorelease];
}
(Note that in a class method, self
refers to the class object.)
However, you would use [[Foo alloc] init]
(that is, an explicit class name) if you actually want an instance of the Foo
class (and not a subclass).