Problem with singleton
I want to make a singleton containing information "title, comments, Two picture" and it saves all the information in an array I want to do is these objects in my application I use it All The Time
@interface CarteManager : NSObject {
NS开发者_开发技巧MutableArray *carteMan ;
}
@property(nonatomic,retain) NSMutableArray *carteMan;
+(CarteManager*)sharedInstance;
-(void)ajouttitre:(NSString*)txt;
-(void)ajoutcom:(NSString*)com;
-(void)ajoutimage1:(UIImage*)img;
-(void)ajoutimage2:(UIImage*)img;
@end
In order to create a Singleton you will need a static instance.
@implementation CarteManager static CarteManager *_carteManager = nil; +(CarteManager*)sharedInstance { if (!_carteManager) { _carteManager = [[CarteManager alloc] init]; } return _carteManager; } // your other codes @end
And before creating a Singleton, make sure that you really need a Singleton. Please pay special attention to Singleton: How should it be used.
You didn't state your problem. If it's how to make the object a singleton, you can find several possible implementations in the question What does your Objective-C singleton look like?.
精彩评论