Ok, j'essaie d'éviter les variables globales, donc je lis des classes singleton. Il s'agit d'une tentative de définition et de lecture d'un tableau mutable, mais le résultat est null.Singleton Class iPhone
//Content.h
@interface Content : NSObject {
NSMutableArray *contentArray;
}
+ (Content *) sharedInstance;
- (NSMutableArray *) getArray;
- (void) addArray:(NSMutableArray *)mutableArray;
@end
.
//Content.m
@implementation Content
static Content *_sharedInstance;
+ (Content *) sharedInstance
{
if (!_sharedInstance)
{
_sharedInstance = [[Content alloc] init];
}
return _sharedInstance;
}
- (NSMutableArray *) getArray{
return contentArray;
}
- (void) addArray:(NSMutableArray *)mutableArray{
[contentArray addObject:mutableArray];
}
@end
Et dans un ViewController j'ajouté #import "Content.h", où je tente d'appeler ceci:
NSMutableArray *mArray = [NSMutableArray arrayWithObjects:@"test",@"foo",@"bar",nil];
Content *content = [Content sharedInstance];
[content addArray:mArray];
NSLog(@"contentArray: %@", [content getArray]);
Parfait, merci pour le code – scud
voté en, a été utile. Merci! – Alex