Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Objective-C 2.0 style question.



I agree to each their own..

For XCode 3.x and Objective C 2.0.. If you have a value the following:

@interface MyAppController : NSObject
{
@private
	NSWindow* myWindow;
}

@property(retain) NSWindow* myWindow;

@end

@implement MyAppController

@synthesize myWindow

-(void) setMyWindow:(NSWindow*)aWindow
{
	NSLog(@"Window was set");

	[myWindow autorelease];
	
	myWindow = [aWindow retain];
}

When you set the myWindow ivar in IB then your setter will get called. This is just an example, not useful code.

Scott

On Apr 22, 2008, at 12:43 PM, Niko Matsakis wrote:

We got into this whole debate in the cocoa dev list about prefixes. I was using them for a while until i started doing Objective C 2.0 work. Then voted against using prefixes in ivars like _, m_, etc. The reasoning for this was i would like the accessors to be used when setting things using interface builder to setup interface objects. This keeps the pattern of using the accessors consistent.

I don't quite understand. Are you saying the IB invokes an accessor if it exists? If so, why not just use the name of the accessor in IB rather than the instance variable name, and keep the naming prefix?


If not, that is if IB just sets the field directly via magic, then it seems to me clearer to have a prefix name that means "no magic", whether it's in IB or in Obj-C source code.

However, I don't feel strongly about it. To each their own. :) I just thought I'd share a technique I've found useful for ensuring that accessors are used consistently.


Niko

_______________________________________________ Do not post admin requests to the list. They will be ignored. Objc-language mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/objc-language/email@hidden

This email sent to email@hidden
References: 
 >Objective-C 2.0 style question. (From: Scott Andrew <email@hidden>)
 >Re: Objective-C 2.0 style question. (From: Niko Matsakis <email@hidden>)
 >Re: Objective-C 2.0 style question. (From: Scott Andrew <email@hidden>)
 >Re: Objective-C 2.0 style question. (From: Niko Matsakis <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.