• 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 and Object
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: GLobal Variables and Object


  • Subject: Re: GLobal Variables and Object
  • From: Joakim Danielson <email@hidden>
  • Date: Wed, 5 May 2004 20:34:58 +0200

An object-oriented solution is to have a Singleton class that you initialize when your app starts. You probably find several examples of how to create a Singleton on this list.
Here is a simple (but not perfect) way:

@implementation MySingleton
+ (MySingleton *) instance {
static id _instance = nil;

if (_instance == nil) {
_instance = [[self alloc] init];
}
return _instance;
}

-(id) init {
self = [super init];
if (self) {
//init your global variables here
}
return self;
}


Joakim

On 5 maj 2004, at 17.48, Eli Hughes wrote:

Hello:

What is the easiest way to instiante an object (for example an NSmutableString)
such that is is visible to ALL functions and methods in a program Is there an
easy way handling this in objective C? How would I then destroy this object at
the end of my program?

How generrally does scope work in objective C? In regular C, if a variable is
defined in a function, it is only visible in that function. In objective C,
are objects created (say in a method of some object) global in scope?

Basically I have application data that I want accessibly to all of my window
controller objects and custom handling objects, etc. What is the safest way to
do this?


Thanks,
Eli hughes
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


References: 
 >GLobal Variables and Object (From: "Eli Hughes" <email@hidden>)

  • Prev by Date: prevent selection of next table cell after hitting return
  • Next by Date: Re: Not skipping Descendents
  • Previous by thread: Re: GLobal Variables and Object
  • Next by thread: Drawing subviews, then the parent view
  • Index(es):
    • Date
    • Thread