Apple Sample directly accesses ivar. Heresy?
Apple Sample directly accesses ivar. Heresy?
- Subject: Apple Sample directly accesses ivar. Heresy?
- From: Jerry Krinock <email@hidden>
- Date: Sat, 18 Feb 2006 07:12:49 -0800
- Thread-topic: Apple Sample directly accesses ivar. Heresy?
Over the past few months I have been getting into the habit of always using
accessors to access instance variables (ivars) within my classes. A
minimalist by religion, I feel this is overly pedantic and "inefficient",
however I have forced myself to do it, because people smarter than me say
that I should, "the message overhead is small", and indeed this discipline
has reduced the number of memory management errors I make.
But yesterday I was looking at some Apple sample code and saw that somebody
at Apple broke the rule in subclassing NSCell:
file://localhost/Developer/Examples/AppKit/DragNDropOutlineView/ImageAndText
Cell.h
line 9:
@interface ImageAndTextCell : NSTextFieldCell {
@private
NSImage *image;
...
file://localhost/Developer/Examples/AppKit/DragNDropOutlineView/ImageAndText
Cell.m
line 97: (There are several such direct accesses in this method)
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView {
if (image != nil) {
NSSize imageSize;
NSRect imageFrame;
imageSize = [image size];
...
There is no explanation of this direct access in comments or ReadMe.
Is this a bad example, or did the author intentionally break the rule in
order to get a little faster drawing performance, since NSCell
-drawWithFrame:inView: is going to get invoked many times in drawing a
table?
Jerry Krinock
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden