Mailing Lists: Apple Mailing Lists

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

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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to 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.