ios - Retrive value from plist file based on date -
i have been searching how while no luck.. how can retrieve value stored in plist file according today's date checked against key in plist file.

for example date today 2013-05-10 code should output 5 console (the corresponding key in plist file. or eg. date today 2013-05-13 code should output 6 console(the corresponding key in plist file.
here's code load plist file dictionary:
nsstring *something = [[nsbundle mainbundle]pathforresource:@"calender" oftype:@"plist"]; _calender = [[nsdictionary alloc]initwithcontentsoffile:something]; nsdate *eventdate = [_calender objectforkey:@"date"];
your dictionary has date strings keys , corresponding values strings.
your code load dictionary fine. part missing generating proper key current date.
nsdateformatter *df = [[nsdateformatter alloc] init]; // use special locale when generating fixed format date strings nslocale *posix = [[nslocale alloc] initwithlocaleidentifier:@"en_us_posix"]; [df setlocale:posix]; [df setdateformat:@"yyyy-mm-dd"]; nsstring *datestring = [df stringfromdate:[nsdate date]]; now can use datestring key dictionary lookup value:
nsstring *datevalue = _calender[datestring]; // using misspelling of calendar datevalue @"5", @"6", or nil. nil if today's date isn't in dictionary.
Comments
Post a Comment