• 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: Accessing variables across classes
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Accessing variables across classes


  • Subject: Re: Accessing variables across classes
  • From: Andrew Farmer <email@hidden>
  • Date: Sun, 18 May 2008 22:22:58 -0700

On 18 May 08, at 22:06, Brett Powley wrote:
MyAppDelgate *ad = [NSApp delegate];
then do something with [ad myMutableArray]

Incorrect. You don't get accessors for instance variables automatically like that.


To the original poster, there are three approaches you can go with here.

One is to set the variables as @public in the ApplicationDelegate, then access them as applicationDelegate->theArray. This breaks encapsulation, but it works.

Another approach is to write accessor methods on the ApplicationDelegate to return the arrays and use those. This requires some extra code.

Finally, if you're targeting Leopard, you can use properties. These can be put together without any extra code, and they don't break OO like @public variables do.
_______________________________________________


Cocoa-dev mailing list (email@hidden)

Please 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: Accessing variables across classes
      • From: Andrew Merenbach <email@hidden>
    • Re: Accessing variables across classes
      • From: Brett Powley <email@hidden>
References: 
 >Accessing variables across classes (From: Joey None <email@hidden>)
 >Re: Accessing variables across classes (From: Brett Powley <email@hidden>)

  • Prev by Date: Re: Is there an NSCollectionView selection change notification?
  • Next by Date: Re: Accessing variables across classes
  • Previous by thread: Re: Accessing variables across classes
  • Next by thread: Re: Accessing variables across classes
  • Index(es):
    • Date
    • Thread