I am somewhat new to iOS 5 singletons and am using a singleton as documented here:
Something like this:
MyManager.h
#import <Foundation/Foundation.h>
@interface MyManager : NSObject
//Data for section 1
@property(nonatomic,copy) NSString * section1a;
@property(nonatomic, assign) NSUInteger section1b;
//Data for section 2
@property(nonatomic,copy) NSString * section2a;
@property(nonatomic, assign) NSUInteger section2b;
+ (id)sharedInstance;
@end
MyManager.m
@implementation MyManager
@synthesize section1a, section1b, section2a; , section2b;
+ (id)sharedInstance
{
static dispatch_once_t pred = 0;
__strong static id _sharedObject = nil;
dispatch_once(&pred, ^{
_sharedObject = [[self alloc] init]; // or some other init method
});
return _sharedObject;
}
@end
So I use it as follows:
MyManager * myManager = [MyManager sharedInstance];
myManager.data = self.data
Is this how you generally use the singleton? Am I missing anything? Sorry for the basic questions I just want to make sure I am doing it right.
Thanks