Sara
Sara

Reputation: 35

Does "alloc" methods produce an instance ?

When I write:

MyClass *obj = [[MyClass alloc]init];

I can split in 2 parts:

So alloc is a Class methods and being init an instance method i suppose that it must be called on an instance...in this case the result of [MyClass alloc]. I'm really confused about that.

Are my conjectures correct?

Upvotes: 0

Views: 55

Answers (2)

Familiar with C++? +alloc = new. -init… = constructor method.

Upvotes: 0

Jonathan Grynspan
Jonathan Grynspan

Reputation: 43472

+alloc allocates and zeroes the memory for an instance of a class. This instance is uninitialized—it's not ready to be used as an object until you initialize it with -init or related.

Upvotes: 4

Related Questions