Re: Regarding MVC design pattern
Re: Regarding MVC design pattern
- Subject: Re: Regarding MVC design pattern
- From: Jack Nutting <email@hidden>
- Date: Wed, 19 May 2010 11:28:34 +0200
On Wed, May 19, 2010 at 11:17 AM, Sai <email@hidden> wrote:
> Hi Jack,
> Thank you for your quick response. Your answer is very useful.
> Since I have pasted some of my codes in the previous mail. I just
> wonder if you have any comments on my codes, anything I can
> improve for this little app? Any advice will be very appreciated.
Sure, I actually spotted a few things when I went back and looked.
First of all, make modelNames a @property, and @synthesize it in your
implementation. Then:
- (void) initModelNames {
/* setup two NSArray: strNames, strKeys */
self.modelNames = [NSDictionary dictionaryWithObjects:strNames
forKeys:strKeys];
//
// was this:
// modelNames = [[NSDictionary dictionaryWithObjects:strNames
forKeys:strKeys] retain];
//
// Using the property instead gives you more consistency, and even
allows you to
// safely call this method later if you need to.
}
- (void) dealloc {
self.modelNames = nil;
//
// was this:
// [modelNames release];
// modelNames = nil;
//
// Using the property instead, you both release it and clear out
the variable at once.
[super dealloc];
NSLog(@"MyModel dealloc method invoked!"); //dealloc checkpoint 2
}
Unrelated to the myModel property, this must must be fixed:
- (id) initWithNumber(int)numValue {
if (self = [super init]) {
self.number = numValue;
[self initModelNames];
}
return self;
//
// was this:
// return [self autorelease];
//
// "self" is not something you've received from an alloc or copy
method, nor have you
// sent it a retain, so you must not release it! I'm somewhat
surprised this even worked.
}
--
// jack
// http://nuthole.com
// http://learncocoa.org
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden