YasBES
YasBES

Reputation: 2325

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 {


NSMutableArray *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

Upvotes: 0

Views: 576

Answers (2)

taskinoor
taskinoor

Reputation: 46027

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.

Upvotes: 1

DarkDust
DarkDust

Reputation: 92316

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?.

Upvotes: 0

Related Questions