The following seems to be working out for me.

#import "AppCommon.h"
@implementation AppCommon
+ (AppCommon *)shared
{
    static AppCommon *shared = nil;
    static dispatch_once_t token;
    dispatch_once(&token, ^{
        shared = [[self alloc] init];
    });
    return shared;
}

-Carl


> On Dec 1, 2015, at 4:55 PM, Quincey Morris 
> <quinceymor...@rivergatesoftware.com> wrote:
> 
> On Dec 1, 2015, at 12:58 , Carl Hoefs <newsli...@autonomy.caltech.edu 
> <mailto:newsli...@autonomy.caltech.edu>> wrote:
> 
>> available to all classes via [[UIApplication sharedApplication] delegate].
> 
>> Are there any drawbacks to this?
> 
> I don’t find this practice very objectionable, but the drawback is that 
> '[[UIApplication sharedApplication] delegate]’ has the wrong class, so you 
> usually end up writing some sort of global function to get it pre-cast.
> 
> In that case, you may as well use a different object, make it a local static 
> variable in a class implementation, and write a static method 
> (“[MyContextCache sharedContextCache]”) to get it. Don’t forget to use 
> dispatch_once to create the singleton. You may not have any thread safety 
> concerns right now, but you might easily do so later.
> 
> 

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to