jaleel
jaleel

Reputation: 307

iphone read from file

i create a view based application , in this project i want read data from .plist file.

how it is possible,

Pleas help me ?

Upvotes: 0

Views: 131

Answers (2)

Dhaval Parmar
Dhaval Parmar

Reputation: 121

NSString *path = [[NSBundle mainBundle] pathForResource:@"plistfilename" ofType:@"plist"];
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@", path]];

NSString *body = [dict objectForKey:@"Keyname"];

with the use of this anyone can read data from plist file.

Upvotes: 4

kennytm
kennytm

Reputation: 523154

If you are sure the .plist file is a dictionary at root level,

return [NSDictionary dictionaryWithContentsOfFile:@"path/to/your.plist"];

otherwise,

NSData* plist_data = [NSData dataWithContentsOfFile:@"path/to/your.plist"];
return [NSPropertyListSerialization propertyListFromData:plist_data mutabilityOption:NSPropertyListImmutable format:NULL errorDescription:NULL];

Upvotes: 0

Related Questions