Re: Best practices with singletons
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