How to create a convenience method for creating an object

Discussion in 'Mac Programming' started by BadWolf13, Jan 22, 2011.

  1. BadWolf13 macrumors 6502

    Joined:
    Dec 17, 2009
    #1
    I'm working on a class that I think would benefit from a convenience method, the same way that NSNumber, NSString and NSArray have for creating the object. Can't figure out how. The only thing I can find from a google search is someone suggesting that you call the init method with an autorelease. Like so:

    Code:
    + stringWithFoo: (Foo *) aFoo
    {
         return [[[self alloc] initWithFoo: aFoo] autorelease];
    }
    Is this really the best way to do it?
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000

Share This Page