Reputation: 17591
In my project I must store a value for a period; Example: I have three buttons where I can choose a value: I have a button for "10" another for "100" and another for "1000". When I press a button I open a view where I can choose a period for these value: then for example I press "100", and I select period by 15/05/2011 at 20/05/2011 and press ok. The result is that at the month "May" in day 15 there is value 100, in day 16 there is value 100.....and in day 20 there is value 100. Can I organize this method with an array of month where in an index there is another array of days and inside every days there is the value 100? But I don't know how to do this...Can you help me?
Upvotes: 0
Views: 4655
Reputation: 529
From what I gather in your question... you basically want an array of months, and within each month you have an array of days, and for each day you have an array of values? or just the value?
Either way, what you can do is just nesting arrays. So you have one NSArray, and all the objects within that NSArray are also NSArrays and so on and so forth until you get the structure you want.
If you could provide a more clear explanation of what exactly you wish to achieve then I might be able to elaborate on my answer, but I think this might get you onto the right track?
NSMutableArray *months = [[NSMutableArray alloc] init];
for (int i = 0; i < 12; i++) {
NSMutableArray *days = [[NSMutableArray alloc] init];
for (int j = 0; j < 30; j++) {
NSMutableArray *values = [NSMutableArray alloc] init];
[days addObject:values];
[values release];
}
[months addObject:days];
[days release];
}
I don't have my mac around so forgive me for any errors, but I think you want something like this?
So in the "months" array, there are 12 "days" arrays, and for each "days" array, there are 30 "values" arrays where you can add your values.
NOTE: You will have to put in your logic to check for the actual amount of days there are in each month, as this code will just assume every month has 30 days.
Upvotes: 2