plist

2012-04-28 17 views
6

'dan bir değer elde etme yöntemi NumberX adında bir tamsayım ve PlistX adında bir plist var.plist

Örnek

int NumberX; 

PlistX:

plist

ben Three

cevap

15

bu deneyin:

NSString *path = [[NSBundle mainBundle] pathForResource:@"PlistX" ofType:@"plist"]; 
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path]; 
int number = [[[[dict objectForKey:@"One"] objectForKey:@"Two"]objectForKey:@"Three"] intValue]; 
NSLog(@"%d",number);  
3

1 NumberX = değer yapmak istiyorum nasıl merak) alın veriler (yani NSMutableDictionary *) plist diske kaydedildi:

NSMutableDictionary *dictionary = [NSPropertyListSerialization propertyListFromData:data mutabilityOption:NSPropertyListMutableContainers format:NULL errorDescription:&error]; 

2) İstenen nesneyi sözlükten al.

//in your case 
NSNumber *tmpNumber = [[[dictionary objectForKey:@"One"] objectForKey:@"Two"] objectForKey:@"Three"]; 
// convert to int 
int NumberX = [tmpNumber intValue]; 
+0

Hasta daha sonra bu deneyin, hızlı yanıt için teşekkürler. – akuritsu

İlgili konular