• 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
Followup - Re: Is there a pattern for creating an object with global scope?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Followup - Re: Is there a pattern for creating an object with global scope?


  • Subject: Followup - Re: Is there a pattern for creating an object with global scope?
  • From: YT <email@hidden>
  • Date: Sat, 13 Apr 2013 21:08:41 -0700

First just to clear a distraction...

I didn't want to actually create my own version of Preferences.  In fact that was a mistake to even mention it.  Sorry, I was flailing in my mind trying to describe what I was struggling with and out came Preferences as an example.  Totally throw away the notion of creating a Preferences Object.

My struggle is partially due to my lack of experience in OOP. I just have not written enough OO code as of yet.  AND I'm very new to Objective-C. Hence my lack of experience and working knowledge of Objective-C.

Scott Ribe sited a working example that I could instantly understand, since I have lots of experience in good 'ole Standard C.

Yes, extremely easy, just "create" the var, as in:

int gFoobar = 42;

Then reference it elsewhere as:

extern int gFoobar;

I understand that solution and its working for me right now.  I have a PreRun Class that defines the object and I instantiate in main.m just before the line
return NSApplicationMain(argc, (const char **)argv);
runs in main.m.  The object instance persists the entire program run. THEN I simply extern the global var that holds the pointer to the object in all of the Class files where its required to access it.

It may be a violation of OOP theory and application, it may be considered a kludge BUT it works right now.  I am willing to move to a conventional OOP solution if I could figure out how.

Reading Apple Documentation is like reading UNIX Man pages - groan, beat me with a stick but don't make me read UNIX Man Pages - sigh.

As suggested I read "some" on NSUserDefaults - I'm not sure how this would provide what I need, perhaps more reading here.

As Suggested I looked up the notion of a Singleton and Creating a Singleton Instance - Looks promising BUT since I have little experience to date on deciphering Apple Objective-C documentation it has created more unanswered questions rather than producing working code. SIGH!  More reading in my future and stumbling in the dark.

YT





.




_______________________________________________

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: Followup - Re: Is there a pattern for creating an object with global scope?
      • From: Graham Cox <email@hidden>
    • Re: Followup - Re: Is there a pattern for creating an object with global scope?
      • From: Steve Mills <email@hidden>
References: 
 >Is there a pattern for creating an object with global scope? (From: YT <email@hidden>)

  • Prev by Date: Re: multiple profiles in preferences mechanism
  • Next by Date: Re: Followup - Re: Is there a pattern for creating an object with global scope?
  • Previous by thread: Re: Is there a pattern for creating an object with global scope?
  • Next by thread: Re: Followup - Re: Is there a pattern for creating an object with global scope?
  • Index(es):
    • Date
    • Thread