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

Re: Best practices with singletons


  • Subject: Re: Best practices with singletons
  • From: Jens Alfke <email@hidden>
  • Date: Sun, 08 Jun 2014 10:04:55 -0700

On Jun 8, 2014, at 9:30 AM, William Squires <email@hidden> wrote:

> 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?

I wouldn’t recommend early initialization of shared instances, because it causes classes to get initialized earlier, slowing down launch time (a bit) and defeating the purpose of the lazy initialization.

And in general, initialization related to a particular class should go into a +initialize method, not in main().

>  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?

If you want to indicate that you’re explicitly ignoring a return value, the idiom is to cast it to void:
	(void)[MyClass sharedController];

—Jens
_______________________________________________

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


References: 
 >Best practices with singletons (From: William Squires <email@hidden>)

  • Prev by Date: Best practices with singletons
  • Next by Date: File's owner in nib file
  • Previous by thread: Best practices with singletons
  • Next by thread: Re: Best practices with singletons
  • Index(es):
    • Date
    • Thread