views:

141

answers:

1

I am bothered by the following code snippet in my program.

If I write

mo=[[myObj alloc] init];

it fails, but if I write

mo=[myObj alloc];
mo=[mo init];

it works. These two methods are supposed to be equivalent but somehow I am messing up. Any light?

Clarifications:

myObj is the name of a class

It fails by trying to allocate for a different kind of object, failing to find the right methods and finally crapping out far from the initialization.

+3  A: 

I think this may happen only when the -(id)init method is overwriten wrong in the myObj Class. Maybe you don't return self; or you don't have the returning type (id). If none of this is right, please provide more details about how the -(id)init method is implemented.

mxg
+1 from me. This sounds like a good guess as to why it would fail only in the one case. Good thinking!
e.James