• 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
Re: Collection of Cocoa & objc questions from a "newbie"
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Collection of Cocoa & objc questions from a "newbie"


  • Subject: Re: Collection of Cocoa & objc questions from a "newbie"
  • From: Chris Gehlker <email@hidden>
  • Date: Mon, 16 Jul 2001 18:38:06 -0700

On 7/16/01 4:21 PM, "tyler" <email@hidden> wrote:

> Hi All,
> So I've been working through the Learning Cocoa book and have
> generated the following questions regarding the Dot View example
> application in Ch 8.
>
>
> Several curious things.
>
>
> 1) Objective C: it appears that methods do not really need to be
> declared in the .h file of objective C files in order for them to get
> compiled and called by other classes.
>
> 1a) the inherited methods awakeFromNib, initWithFrame and so on seem to
> get called for the DotView custom view even though I chose not to type
> them into the DotView.h file.
>
> 1b) the custom methods I defined that controls are using as action
> methods seem to be callable without declaring them in the DotView.h file
> as well.
>
> 1c) the DotView.m file compiles just fine with methods that are NOT
> declared in the .h file.
>
>
> How is this possible? I'm used to c/c++/pascal/etc that require a
> declaration to even compile.

There are a few things going on here. Methods that your classes inherit are
declared in Cocoa.h. Also ObjC methods are more like C or C++ functions than
C++ methods in that a definition is a declaration in ObjC while only an
inline definition is a declaration in C++. So as long as the method is
defined before it is used in a .m file, the compiler won't complain.

I found this very strange at first too.

> 2) If I set breakpoints in the DotView custom View I see that several
> methods are called twice (awakeFromNib and initWithFrame in
> particular). It appears the the "self" value in the debugger has
> changed so I'm guessing that one call is for the "proxy" object created
> due to the nib (not that I really understand what that means, just read
> it somewhere), and one is the real object that I defined and that the
> proxy instantiates (???).

I'm not seeing this.

> 3) If I set a breakpoint in the (void)dealloc method for the DotView
> custom view, it is never called (close window, quit app, never called).
>
> Does this mean that code in a dealloc method may never be called in
> general and shouldn't be counted on getting called?

I see the same thing that you do. I think it's probably a problem with gdb
but I can't prove it.
--
Heaven is under our feet as well as over our heads. -Henry David Thoreau,
naturalist and author (1817-1862)


References: 
 >Collection of Cocoa & objc questions from a "newbie" (From: tyler <email@hidden>)

  • Prev by Date: Flame war
  • Next by Date: Re: Learning Cocoa (OT!: Small Language Rant)
  • Previous by thread: Re: Collection of Cocoa & objc questions from a "newbie"
  • Next by thread: RE: Learning Cocoa (OT!: Small Language Rant)
  • Index(es):
    • Date
    • Thread