views:

1282

answers:

2

I want to write some methods in a class so that other classes can call these methods using [instance methodName:Parameter].

If the class is a subclass of UIViewController, I can use initWithNibName to initialize it. But I want to write the methods in an NSObject's subclass, how can I initialize it?

A: 

I find this may work:

TheClass *newObject = [[TheClass alloc] init];
//do something here
[newObject release];
iPhoney
+4  A: 

iphony is correct, but he or she doesn't say that you need to write the init method yourself. Your init method should generally look something like this:

- (id) init
    {
    if (self = [super init])
         {
         myMember1 = 0; // do your own initialisation here
         myMember2 = 0;
         }
    return self;
    }
Jane Sales