0

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?

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

yes, I 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, because in every days I can store some values and not only one. Can you suggest me an example how can I orgnanize my code?
I've modified my answer to show some sample code which will give you an array that should achieve what you want to do I believe
yes that's right, this is for one year. If you want it over multiple years then you will have to create another array and add the months array into that one.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.