Saturn
Saturn

Reputation: 18139

Reading a string from a .plist file error

data = [NSDictionary dictionaryWithContentsOfFile:
            [[NSBundle mainBundle] pathForResource:@"INFO" ofType:@"plist"]];
    name = [[data objectForKey:@"Name"]stringValue];

I am getting a SIGABRT error on when I try to give create name. All the names are alright. What could be wrong?

I have a INFO.plist file in my project. It has a row of type String. The value is Test.

Upvotes: 3

Views: 2392

Answers (1)

NSGod
NSGod

Reputation: 22948

Provided name is an NSString *, the following ought to work:

NSString *name = [data objectForKey:@"Name"];

NSDictionary's -objectForKey: returns the object, which will already be an NSString. (I'm not sure why you're calling -stringValue on it, but that could cause a crash or exception).

Upvotes: 6

Related Questions