Re: Proper way to create a singleton without @synchronized ?
Re: Proper way to create a singleton without @synchronized ?
- Subject: Re: Proper way to create a singleton without @synchronized ?
- From: Joanna Carter <email@hidden>
- Date: Mon, 18 Apr 2011 18:46:45 +0100
Hi Steven
> How? If you don't have an instantiation of the class you don't have
> anywhere to store the data.
> Either I am misunderstanding what you are saying or you are missing my
> suggestion of class methods.
> Perhaps you could explain?
// StaticClass.h
@interface StaticClass : NSObject
{
}
+ (NSManagedObjectContext *) managedObjectContext;
@end
//StaticClass.m
@implementation StaticClass
static NSManagedObjectContext *managedObjectContext = nil;
+ (NSManagedObjectContext *) managedObjectContext
{
if (!managedObjectContext)
{
… // create and setup
}
return managedObjectContext;
}
@end
This can then be accessed from other code as…
{
NSManagedObjectContext *context = [StaticClass managedObjectContext];
…
}
Joanna
--
Joanna Carter
Carter Consulting
_______________________________________________
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