• 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: init vs awakefromnib
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: init vs awakefromnib


  • Subject: Re: init vs awakefromnib
  • From: Keith Duncan <email@hidden>
  • Date: Sun, 11 Mar 2007 00:25:54 +0000

The best place to set a class variable is in the + (void)initialize; method.

However, if the variable is only needed in a single method its better to declare it as a static variable inside the method, that way you avoid polluting the global namespace.

That said I can't see why the method you create it in would matter, so long as the object you are pointing it too has a retain count of 1 (and is not autoreleased) and you don't release it: it should stick around for the duration of your app's execution.

How are you declaring the class variable? How are you assigning it?

- Keith

On 10 Mar 2007, at 23:44, Ahmet Taha Sakar wrote:

I have a NSWindowController subclass. In this class I have created a
NSMutableArray class variable. If I alloc and init this variable in init
method of the class it gets released after awakefromnib and therefore I can
not use it later. However if I alloc and init the variable in awakeFromNib,
it gets retained as I wanted and I can use it later.


So these are my questions:
1) Why does the location of alloc and initilizaing a class variable code
make this difference?
2) Arent all class variables automaticaly retained until the whole class is
released?
3) What's the way to allocate and initialize the class variable in init
method of the class to be able to use it with other methods later. I have
tried adding retain, but it hasnt worked.



Thanks
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: init vs awakefromnib
      • From: "Ahmet Taha Sakar" <email@hidden>
References: 
 >init vs awakefromnib (From: "Ahmet Taha Sakar" <email@hidden>)

  • Prev by Date: init vs awakefromnib
  • Next by Date: Re: init vs awakefromnib
  • Previous by thread: init vs awakefromnib
  • Next by thread: Re: init vs awakefromnib
  • Index(es):
    • Date
    • Thread