0

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
visakh7
  • 26,380
  • 8
  • 55
  • 69
YasBES
  • 2,365
  • 3
  • 21
  • 33

2 Answers2

1

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.

Community
  • 1
  • 1
taskinoor
  • 45,586
  • 12
  • 116
  • 142
0

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

Community
  • 1
  • 1
DarkDust
  • 90,870
  • 19
  • 190
  • 224