You can do the following, in your implementation file create a local procedure and then call it from your init method. I did not bother copying your arguments but you define them in the regular way.
-(void)myCalculation { // do the calculation } - (id) init { if ( self = [super init] ) { // do your init var3 = [self myCalculation]; } return self; } On Jan 12, 2011, at 3:41 AM, Luc Van Bogaert wrote: > Hi, > > I have a question about how to design a initializer mehod. > > I have defined a class with three instance variables. Two of them are arrays > and their value can be initialized straightforward in the initializer method, > but the value of the third instance variable is the result of a complex > algorithm, based on the contents of the two arrays. > > I would like to implement that algorithm in a seperate method, instead of > writing it directly in the initializer. Is that OK, and could I then message > "self" in the initializer like: > > - (id) init > { > self = [super init]; > if (self) { > var1 = ...; > var2 = ...; > var3 = [self computerVar3With:var1:var2]; > } > return self; > } > > Or is it better to write the algorithm directly as part of the initializer? > Thanks, > > -- > Luc Van Bogaert > luc.van.boga...@me.com > > _______________________________________________ > > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) > > Please do not post admin requests or moderator comments to the list. > Contact the moderators at cocoa-dev-admins(at)lists.apple.com > > Help/Unsubscribe/Update your Subscription: > http://lists.apple.com/mailman/options/cocoa-dev/phystad%40mac.com > > This email sent to phys...@mac.com _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com