small medium large xlarge

Generic-user-small
02 Dec 2009, 05:41
Vincent Cirilli (2 posts)

Utility Class Methods pg.139

Following this convention on our own object, we’ll call the class method “wonderfulNumberWithFloat:.” This makes it clear that we will return an autoreleased WonderfulNumber object, initialized using a provided float argument.

I’m not following the “This makes it clear that we will return an autoreleased WonderfulNumber object” part.

Is it because the naming convention «objectType»With«optional arguments:» is always used in initializing methods that return an autoreleased object.

So then if I saw NSWindingWithInteger I could assume it would return a autoreleased NSWinding object without having to check any documentation?

Generic-user-small
10 Dec 2009, 21:41
Tim Isted (105 posts)

I’m sorry that I haven’t replied until now; for some reason your post didn’t show up in my feeds.

Yes, if you don’t create the object using an @alloc] init…]@ call (or use a @copy@ method), but instead use a class method following @«objectType»With«optional arguments:»@, the convention should always be that you will be returned an autoreleased object.

In your @NSWinding@ example, you would likely have the @NSWinding@ class have a method named @windingWithInteger:@ which would return an autoreleased @NSWinding@ instance.

You must be logged in to comment