Benoit
Benoit

Reputation: 3

NSDictionary string casting

I've manually written a .plist file with a dictionary. My problem is that the value for the key "route_id" returned is wrong. I get a "1" in place of "01".

Here my dict :

<dict>
<key>route_desc</key>
<integer>1</integer>
<key>route_id</key>
<string>01</string>
</dict>

Here my code :

NSLog(@"%@", [selectedRoute valueForKey:@"route_id"]);

Return 1 and not 01;

If anyone can help me to get the right value !

Upvotes: 0

Views: 178

Answers (1)

Dave DeLong
Dave DeLong

Reputation: 243146

I'm not sure what you're doing, but you're messing things up somewhere. I saved the plist to my desktop and ran:

NSDictionary * d = [NSDictionary dictionaryWithContentsOfFile:@"/Users/dave/Desktop/test"];
NSLog(@"%@", d);
NSLog(@"%@", [d valueForKey:@"route_id"]);
NSLog(@"%@", [d objectForKey:@"route_id"]);

And got:

2011-01-10 14:35:55.437 EmptyFoundation[15631:a0f] {
    "route_desc" = 1;
    "route_id" = 01;
}
2011-01-10 14:35:55.440 EmptyFoundation[15631:a0f] 01
2011-01-10 14:35:55.440 EmptyFoundation[15631:a0f] 01

Upvotes: 2

Related Questions