• 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: Joanna Carter <email@hidden>
  • Date: Wed, 19 May 2010 11:31:08 +0100

Hi Guys

Can I just suggest something more?

> @interface Controller : NSObject {
>    IBOutlet UIButton *beginButton;
>    IBOutlet UIButton *endButton;
>    IBOutlet UILabel *nameLabel;
>    IBOutlet UILabel *numberLabel;
>    MyModel *myModel;
> }
>
> @property (nonatomic, retain) IBOutlet MyModel *myModel;
>
> /* some methods defined here as well */
> @end


From what I have read, and from good object-oriented practice, it would be better to use Objective-C 2.0 properties for all your outlets. iVars really should be @private, if you are using them, but don't forget that properties will synthesize, not only the accessors, but the ivars as well.
@interface Controller : NSObject
{
}

@property IBOutlet UIButton *beginButton;

@property IBOutlet UIButton *endButton;

@property IBOutlet UILabel *nameLabel;

@property IBOutlet UILabel *numberLabel;


@property MyModel *myModel;

/* some methods defined here as well */

@end

@implementation Controller

@synthesize beginButton;

@synthesize endButton;

@synthesize nameLabel;

@synthesize numberLabel;

@synthesize myModel;

@end

Any outlets for controls (top level objects) in the Nib should be released in the dealloc method only for OS X apps but not for iPhone apps. Setting the properties to nil will ensure that the synthesized setter will be called, which releases the previous contents of the synthesized ivar before setting it to nil.

- (void) dealloc
{
  beginButton = nil;

  endButton = nil;

  nameLabel = nil;

  numberLabel = nil;

  myModel = nil;

  [super dealloc];
}

Joanna

--
Joanna Carter
Carter Consulting

_______________________________________________

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

  • Follow-Ups:
    • Re: Regarding MVC design pattern
      • From: Sherm Pendley <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>)

  • Prev by Date: Re: rendering PDF on iPad's
  • Next by Date: Re: Original iPhone animation performance
  • Previous by thread: Re: Regarding MVC design pattern
  • Next by thread: Re: Regarding MVC design pattern
  • Index(es):
    • Date
    • Thread