Erakk
Erakk

Reputation: 922

objectForKey not returning anything

-(NSMutableDictionary *)request:(NSString *)requestString {
    NSString *filepath = [[NSBundle mainBundle] pathForResource:requestString ofType:@"xml"];
    NSError *error = nil;
    respString = [NSString stringWithContentsOfFile:filepath usedEncoding:nil error:&error];
NSLog(@"Ping xml");
    tempDict = [[NSMutableDictionary alloc] initWithDictionary:[parser readXMLString:respString]];
    NSLog(@"%@",tempDict);
return tempDict;
}

Until there, everything is ok, the NSLog is showing that there are 2 objects and keys in the tempDict. But then:

-(int) authenticateUser {
    NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] initWithDictionary:[self request:@"login"]];
    if ([[dictionary objectForKey:@"sessionId0"] isEqualToString:@"-1"] ) {
        //Some code
    }
    else {
        cError = 1;
        NSLog(@"%@",[dictionary objectForKey:@"sessionId0"]);
        appDelegate.sessionId = [dictionary objectForKey:@"sessionId0"];
    }
    [dictionary release];
    return cError;
}

At the last else, where cError is 1, NSLog outputs nil for that object. (NSLog for the entire dictionary also outputs nil)

Upvotes: 0

Views: 261

Answers (1)

ARC
ARC

Reputation: 1804

Place this code in your and see what the output is for dict object...

-(int) authenticateUser {
NSDictionary* dict = (NSDictionary *)[self request:@"login"];
NSLog(@"Dictionary %@",dict);    

NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] initWithDictionary:[self request:@"login"]];
    if ([[dictionary objectForKey:@"sessionId0"] isEqualToString:@"-1"] ) {
        //Some code
    }
    else {
        cError = 1;
        NSLog(@"%@",[dictionary objectForKey:@"sessionId"]);
        appDelegate.sessionId = [dictionary objectForKey:@"sessionId"];
    }
    [dictionary release];
    return cError;
}

Upvotes: 1

Related Questions