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