• 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: Newbie question regarding Learning Cocoa
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Newbie question regarding Learning Cocoa


  • Subject: Re: Newbie question regarding Learning Cocoa
  • From: David P Henderson <email@hidden>
  • Date: Mon, 4 Jun 2001 12:01:50 -0400

If you haven't read Objected-Oriented Programming and the Objective-C Language, you should. It would have answered many of these questions. The book was installed with the Dev Tools in both html and pdf format; it is also available from the Apple Dev Connection site for Cocoa documentation. It is also available in hardcopy from fatbrain.com.

On Monday, June 4, 2001, at 10:17 , Philippe de Rochambeau wrote:

What is the purpose of creating an autorelease pool in the code above if
you are simply printing 'Hello World' onscreen?

If that is the whole of the code, none; other than, to show what it looks like.

color = [[ NSColor redColor] retain];
why do you retain the new NSColor object?

Because the redColor method is a class factory method which returns an autoreleased object. If you want the 'color' object to persist you must retain it explicitly.

return self;
why do you retain 'self'? Why do you return it in an 'id'?

You aren't retaining self unless you left out a line. Self and super are both referring to the same object, the current instance receiving the message, they differ in where they begin the search for a method definition. Sending to self causes the search to begin in the current class while super causes the search to begin in the parent class of the current class. As to returning self here, the init* method is defined as return a type of id which is a generic object, so you return self which is a reference to the current object ie, the one created by the init* method.

[super dealloc];
what is DotView's parent, which you must dealloc?

Which ever class DotView is subclassing.

Does deallocing simply mean calling DotView's parent's dealloc method?

Yes.

[colorWell setColor: color];
how can you be sure here that 'color' points to an existing object? Did you retain it somewhere else?

Because you initialized it in your init* method, and you also retained it. When you declare an instance variable like 'color', it gets initialized to nil unless you do otherwise, and in Obj-C sending messages to nil or passing nil is a okay unless the method definition states otherwise.

[[NSColor whiteColor] set]
why don't you retain the new whiteColor object here, as you did above?

You only want to retain objects which you need to reuse.

[[NSColor whiteColor] set]
what is 'set'? Was it predefined somewhere?

An object of type NSColor is receiving the set message. So you could look up the docs for NSColor to see if it implements a 'set' method.

return [NSCalendarDate date]
what is 'date'? Is it a function?

No a function looks the same in in Obj-C as it does in C. date(). This is a message where NSCalendarDate is the receiving object and date is the method which you want NSCalendarDate to perform.

Dave
--
Chaos Assembly Werks
"Suburbia is where the developer bulldozes out the trees, then names the streets after them."
- Bill Vaughn


References: 
 >Newbie question regarding Learning Cocoa (From: Philippe de Rochambeau <email@hidden>)

  • Prev by Date: Re: Newbie question regarding Learning Cocoa
  • Next by Date: how to disable an indeterminate progress bar?
  • Previous by thread: Re: Newbie question regarding Learning Cocoa
  • Next by thread: Re: Newbie question regarding Learning Cocoa
  • Index(es):
    • Date
    • Thread