Usually, when we have to link an interface element to a field of a class, we use the keyword ‘IBOutlet’ to inform the pre-copiler:
@interface MyController : NSObject {
IBOutlet NSWindow *theWindow;
}
and in the implementation we use directly the pointer theWindow to call methods of the class NSWindow!
But what are the advantages of tell to the pre-compiler to create some accessors to the object that is pointed by “theWindow” and manage the object through the accessors?
Example:
@interface MyController : NSObject {
NSWindow *theWindow;
}
@property(retain) IBOutlet NSWindow *theWindow;
@implementation MyController
@synthesize theWindow;
@end
Does the use of the second solution (for all the pointers to interface’s elements) slows the performances of the application?
When is it a good practice to use the second way instead of the first?
Thank you!
Well in general I don’t retain the properties, and the only way I ever even expose Outlets is if something needs to access an element from the outside, and this is generally a bad sign for your design anyway.
I’ve not tried it but I’d be tempted to only synthesis the read portion, and I’d probably only use it in places where atomic access where important. Some portions of AppKit aren’t always threadsafe.