Reputation: 6176
i have a simple question : why does "origineArray" return (null) ? i found out that if i put all the code in the RootViewController it works, but if i put it in the AppDelegate (as it is in a sample code, i don't which way is better?) , it does not recognize the "Root" key :
- (id)init {
self = [super init];
if (self){
NSString *path = [[NSBundle mainBundle] bundlePath];
NSString *finalPath = [path stringByAppendingPathComponent:@"origine.plist"];
origine = [[NSDictionary dictionaryWithContentsOfFile:finalPath]retain];
}
return self;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSLog(@"origine data : %@", origine);
NSArray *origineArray = [origine objectForKey:@"Root"];
NSLog(@"origineArray data : %@", origineArray);
Thanks for your help
Upvotes: 0
Views: 157
Reputation: 12334
If your application delegate is created in a nib file, the init
method is not called. Items in nibs are archived already initialized.
If you want initialization of an object loaded from a NIB, implement the - (void) awakeFromNib
method.
Upvotes: 1
Reputation: 6991
You are logging the "origine" dictionary, what does it log to the console? If the "Root" key is not there then you are not opening the right file obviously. If the dictionary is NULL then you need to fix the path.
Are you sure that finalPath contains the right path? It seems that the origin.plist is in the resources folder but you are using the location of your app bundle in the finder.
Upvotes: 0