views:

206

answers:

4

I have a very basic data class that is subclassed from NSObject. I declare a few strings, make sure they have properties (nonatomic, copy), and synthesize them. The only method I implemented was dealloc() which releases my strings. Can any memory problems arise from just this? Are there any other methods I need to implement?

+6  A: 

Subclassing NSObject is something that we do all the time. Just follow the memory management rules, and you're good to go.

NSResponder
+1  A: 

You could implement a custom init if you want to set anything up.

-(id)init {
    if (!(self = [super init]))
          return nil;

    // Set things up you might need setting up.
    return self;
}

But that's only if there's something you want to have ready before you call anything else on the class.

Just having a dealloc method should be fine, otherwise.

Tom Irving
+1  A: 

There won't be any problems. Subclassing NSObject is perfectly accepted, and in 99% of cases required.

By subclassing NSObject, your subclass receives all the required behaviour that is expected of any object in Cocoa/Cocoa Touch. This includes things like the reference counting memory management system using retain and release etc.

Jasarien
A: 

What you're doing is fine. Be sure to call [super dealloc] at the end of your subclass' -dealloc method.

Barry Wark