Plist到NSDictionary

时间:2012-08-19 12:24:50

标签: ios cocoa-touch plist nsdate uidatepicker

我有一些plist数据,如下图所示:

enter image description here

如果在UIDatePicker上选择了等于CDate的NSDate,我如何访问“文本”值?

2 个答案:

答案 0 :(得分:12)

所以你基本上想要

NSString* path = [[NSBundle mainBundle] pathForResource:@"file" ofType:@"plist"];
NSArray* a = [NSArray arrayWithContentsOfFile:path]; 
for (NSDictionary *d in a)
{
    NSString *cdate = [d objectForKey:@"CDate"];
    if ([cdate isEqualToString:@"Whatever is currently selected"])
    {
        NSString *text = [d objectForKey:@"Text"];
        // do something with text here
    }
}

答案 1 :(得分:1)

偶然发现了这一点并认为更新已到期

NSDictionary *initialDefaults = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Defaults" ofType:@"plist"]];