• 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 again about basic Obj C
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: newbie question again about basic Obj C


  • Subject: Re: newbie question again about basic Obj C
  • From: Michael <email@hidden>
  • Date: Wed, 5 Nov 2008 19:18:34 -0800

thanks Nick.

On Nov 5, 2008, at 7:06 PM, Nick Zitzmann wrote:

First of all, this has nothing to do with Xcode, and should probably be taken to the cocoa-dev list instead.

But I'll answer your question anyway...

On Nov 5, 2008, at 7:33 PM, Michael wrote:

"alloc" being a class method which allocates memory for the new object. This does not make the object useful because none of its instance variables were initialized...to do that we call "init"...so, the whole thing would go....

id object = [Object alloc];
[object init];

You should always call +alloc and -init on the same line. It's important that an object must be initialized immediately after its memory is allocated.


Now, I understand that alloc returns a pointer to the memory that is allocated to the new object. But, what exactly does "init" do. For example, does init divide the allocated memory to specific areas that represent the instance variables...or is it even more basic that it provides addresses for those variables? Thanks in advance.


-init initializes the object by setting up its instance variables, etc. It does not "divide" memory at all. Think of it as being the rough Objective-C equivalent of a C++ constructor.

Nick Zitzmann
<http://seiryu.home.comcast.net/>




_______________________________________________ Do not post admin requests to the list. They will be ignored. Xcode-users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >newbie question again about basic Obj C (From: Michael <email@hidden>)
 >Re: newbie question again about basic Obj C (From: Nick Zitzmann <email@hidden>)

  • Prev by Date: Re: Time machine does not save the build folder
  • Next by Date: What creates unixdev?
  • Previous by thread: Re: newbie question again about basic Obj C
  • Next by thread: What creates unixdev?
  • Index(es):
    • Date
    • Thread