• 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
Apple Sample directly accesses ivar. Heresy?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Apple Sample directly accesses ivar. Heresy?
      • From: Scott Thompson <email@hidden>
    • Re: Apple Sample directly accesses ivar. Heresy?
      • From: "John C. Randolph" <email@hidden>
  • Prev by Date: Re: warning: C++ constructors and destructors
  • Next by Date: Re: Apple Sample directly accesses ivar. Heresy?
  • Previous by thread: Grinding Images Filter
  • Next by thread: Re: Apple Sample directly accesses ivar. Heresy?
  • Index(es):
    • Date
    • Thread