• 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
Best practices with singletons
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Best practices with singletons


  • Subject: Best practices with singletons
  • From: William Squires <email@hidden>
  • Date: Sun, 08 Jun 2014 11:30:24 -0500

  Okay, I have several classes in my (somewhat large, and growing) project that implement the singleton pattern via a [<classname> shared<whatever>] class method (and a file-scope static reference) that uses lazy loading to instantiate the singleton the first time a reference is asked for. Is it considered better to put all of these calls in the main() function before any other code executes, or not worry about it, and just access them through the above class methods when and where needed?
  Also, in C, it's common to throw away the return value from a function (a la printf(), which returns an int, but coders rarely use the return value), but is it good practice to throw away the result of the above method calls (messages) just to silence the compiler?

i.e.

-(void)someMethod
{
...
[MyClass sharedController]; // No warning here.
...
}

as opposed to:

-(void)someMethod
{
MyClass *p = [MyClass sharedController]; // <- Yellow triangle here for unused variable 'p'
...
}

TIA! :)


_______________________________________________

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: Best practices with singletons
      • From: Dave <email@hidden>
    • Re: Best practices with singletons
      • From: "Glenn L. Austin" <email@hidden>
    • Re: Best practices with singletons
      • From: Graham Cox <email@hidden>
    • Re: Best practices with singletons
      • From: Seth Willits <email@hidden>
    • Re: Best practices with singletons
      • From: Jens Alfke <email@hidden>
  • Prev by Date: Re: Another dumb question about NSWindowController(s)
  • Next by Date: Re: Best practices with singletons
  • Previous by thread: Re: Another dumb question about NSWindowController(s)
  • Next by thread: Re: Best practices with singletons
  • Index(es):
    • Date
    • Thread