• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Regarding MVC design pattern
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

References: 
 >Regarding MVC design pattern (From: Sai <email@hidden>)
 >Re: Regarding MVC design pattern (From: Henry McGilton <email@hidden>)
 >Re: Regarding MVC design pattern (From: Sai <email@hidden>)
 >Re: Regarding MVC design pattern (From: Jack Nutting <email@hidden>)
 >Re: Regarding MVC design pattern (From: Sai <email@hidden>)
 >Re: Regarding MVC design pattern (From: Kyle Sluder <email@hidden>)
 >Re: Regarding MVC design pattern (From: Sai <email@hidden>)
 >Re: Regarding MVC design pattern (From: Jack Nutting <email@hidden>)
 >Re: Regarding MVC design pattern (From: Sai <email@hidden>)

  • Prev by Date: Re: Regarding MVC design pattern
  • Next by Date: Solved BUT How to get NSLog back - Re: NSTask and piped commands -
  • Previous by thread: Re: Regarding MVC design pattern
  • Next by thread: Re: Regarding MVC design pattern
  • Index(es):
    • Date
    • Thread