Paul
Paul

Reputation: 6176

"Root" key from plist is not recognized from the AppDelegate?

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

Answers (2)

codelark
codelark

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

Antwan van Houdt
Antwan van Houdt

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

Related Questions