• 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
IBOutlet getter/setter pattern question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

IBOutlet getter/setter pattern question


  • Subject: IBOutlet getter/setter pattern question
  • From: Eeyore <email@hidden>
  • Date: Sun, 16 Oct 2011 13:53:05 -0700

I noticed that I many of my IBOutlets were only being used to modify the view from the viewDidLoad methods but which were not accessed later in my code. These outlets exist so that I can keep consistent appearance settings in a large number of nibs without actually editing each nib. As a simplified example (typed into Mail, but should describe the pattern), consider the following.

----- begin old style -----
@interface Class : UIViewController
@property (nonatomic, retain) IBOutlet UILabel* label;
@end

@implementation Class
@synthesize label=myLabel;

- (void)viewDidLoad
{
	[super viewDidLoad];

	self.label.textColor = kLabelTextColor;
	self.label.text = NSLocalizedString(@"Blah blah blah", @"Label text");
}

- (void)viewDidUnload
{
	self.label = nil;

	[super viewDidUnload];
}

- (void)dealloc
{
	[myLabel release];

	[super dealloc];
}
@end
----- end old style -----

I have replaced this with the following:

----- begin new style -----
@interface Class : UIViewController
@property (nonatomic, assign) IBOutlet UILabel* label;
@end

@implementation Class
- (void)setLabel:(UILabel*)label
{
	label.textColor = [UIColor lightGray];
	label.text = NSLocalizedString(@"Blah blah blah", @"Label text");

}

- (UILabel*)label
{
	NSAssert(NO, @"label is inaccessible");
	return nil;
}
@end
----- end new style -----

The new style allows me to focus on non-trivial activities in viewDidLoad, viewDidUnload, and dealloc (sometimes even eliminating those methods) and reduces the number of things that need to be memory managed.

So the question: anyone see any problems with this?

Aaron_______________________________________________

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: IBOutlet getter/setter pattern question
      • From: Jerry Krinock <email@hidden>
  • Prev by Date: Re: ARC conversion issue problem with Xcode 4.2
  • Next by Date: Checking for Internet Connection in an iApp
  • Previous by thread: Re: Mac core data and iCloud example app
  • Next by thread: Re: IBOutlet getter/setter pattern question
  • Index(es):
    • Date
    • Thread