• 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: Global variables?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Global variables?


  • Subject: Re: Global variables?
  • From: j o a r <email@hidden>
  • Date: Tue, 27 Dec 2005 12:07:13 +0100


On 27 dec 2005, at 11.55, Matt Reagan wrote:

I understand that in OOP it's generally said to be a bad idea to use
'global' variables outside the normal object-oriented methodology...
but can anyone please advise me on the best way to make a very small
array of integers available to my entire application? I have a main
controller object that had this:

@public
int myIntArray[10];

But despite the public command, I can't seem to access it from another
class. I made sure to include the controller's header file where it's
needed.

What's the easiest way to make some integers available to the whole application?

Easiest or best?

In OOP you have objects, not free floating data. Objects holds data, and methods that acts on their data. So, who is the "owner" of your int array? You can probably build a class to hold that data, in which case you would allow access to that data via methods on that class:

@class MyIntArray : NSObject
{
@private

int myIntArray[10];
}

- (int) intAtIndex:(int) index;
- (void) setInt:(int) integer atIndex:(int) index

@end

You might want to consider implementing this class as a singleton class.

j o a r


Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden
  • Follow-Ups:
    • Re: Global variables?
      • From: Matt Reagan <email@hidden>
References: 
 >Global variables? (From: Matt Reagan <email@hidden>)

  • Prev by Date: Global variables?
  • Next by Date: Re: Global variables?
  • Previous by thread: Global variables?
  • Next by thread: Re: Global variables?
  • Index(es):
    • Date
    • Thread