I communicate with a json api in my cocoa (touch) app.
As a response I get s开发者_开发技巧omething like this:
"wh": {
"1": ["11.30 - 15.00"],
"3": ["11.30 - 15.00"],
"2": ["12.00 - 14.00", "17.30 - 23.00"],
"5": ["11.30 - 15.00"],
"4": ["11.30 - 15.00"]
},
Keys 0 to 6 reflect the weekdays (Monday == 0, Tuesday = 1, ....)
To map this I have a NSArray:
weekdays = [[NSArray alloc] initWithObjects:@"Montag",
@"Dienstag",
@"Mittwoch",
@"Donnerstag",
@"Freitag",
@"Samstag",
@"Sonntag", nil];
I need this in two viewcontrollers - currently set in the viewWillAppear. :(
So my question(s):
- Where/When should I set this weekdays array?
- How to access it in the viewcontrollers?
- Any suggestions?
Why don't you use the NSDateFormatter
class? You can use it to get localized days of the wekk names for any language.
Use a singleton to store that kind of information, here is an example:
http://getsetgames.com/2009/08/30/the-objective-c-singleton/
The way I handle constants in my apps...
1) Create a Common.h file, put it in your Resources directory.
2) Define all the constants you want in there.
#define STATE_INDEX [NSArray arrayWithObjects:@"AL", @"AK", @"AZ", ... nil]
#define NSDATEFORMATTER_WITH_TIME_FORMAT @"dd/MM/yyyy : HH:mm:ss"
#define PORTRAIT_KEYBOARD_HEIGHT 216
3) Make sure to...
#import "Common.h"
in the code files you want to use the constants in.
You could rely in a .strings file:
[[NSBundle mainBundle] localizedStringForKey:key value:key table:@"Weekdays"]
精彩评论