Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5845887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:29:56+00:00 2026-05-22T12:29:56+00:00

I have this code: I want to store some vales in a day of

  • 0

I have this code:
I want to store some vales in a day of the year, I set period for example 15/05/2011 to 20/05/2011

in viewDidLoad:
I store null value then I can store a value everywhere I want in the array, I’m using “sentinel values”:

appDelegate.years = [[NSMutableArray alloc] init];

for (int i = 0; i < 50; i++) // I set 50 years
{
    [appDelegate.years insertObject:[NSNull null] atIndex:i];
}

months = [[NSMutableArray alloc] init];
for (int i = 0; i < 12; i++)
{
    [months insertObject:[NSNull null] atIndex:i];
}

days = [[NSMutableArray alloc] init];
for (int i = 0; i < 31; i++)
{
    [days insertObject:[NSNull null] atIndex:i];
}

In my method:

int firstDay = 15;
int lastDay = 20;
int firstMonth = 4; 
int lastMonth = 4;
NSString *string = first; //this is the value that I want to store in the period


for (int i = firstMonth; i < lastMonth+1; i++) 
{

    for (int j = firstDay; j < lastDay+1; j++)  
    {
        NSMutableArray *values = [[NSMutableArray alloc] init];
            [values addObject:string];
            [days replaceObjectAtIndex:j withObject: values];
            [values release];
    }

    [months replaceObjectAtIndex:i withObject:days];

}

[appDelegate.years replaceObjectAtIndex:0 withObject:months]; //0 is 2011

OK, in this code I store a value in an array “values” that I store in one index of array “days” that I store in one index of array “month” that I store in one index of array “year”, it work fine; but after this, if I want store another string in array values in same position?

Example: I have another NSString *string2 = “second” and I want store this string in the same position of day then I want in same day the array values with “first” and “second”, then I can’t do “[days replaceObjectAtIndex:j withObject: values];” but what Can i do?

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T12:29:57+00:00Added an answer on May 22, 2026 at 12:29 pm

    If I inferred that correctly, you are trying to store a second value at the same day, right?

    If there’s no specific need for laying out your data-structure the way you currently have, I would strongly recommend you just use a plain array with 365 days. What you currently have resembles a tree structure, which is fine too but a pain to implement with arrays (and very inefficient memory wise).

    You seem to forgot that once you have an array initialized at a location in your tree, you can simply append to that existing array.

    Having said that, here’s my input based on your current solution:

    for (int i = firstMonth; i <= lastMonth; i++) 
    {
        for (int j = firstDay; j <= lastDay; j++)  // use <= instead of + 1, it's more intuitive
        {
            NSMutableArray* values = [days objectAtIndex:j];
            if (values == nil)
            {
                values = [[NSMutableArray alloc] init];
                [days insertObject:values atIndex:j];
            }
            [values addObject:string];
            [values release];
        }
        // This is unnecessary. days will never be something else than the current i-var days.
        //[months replaceObjectAtIndex:i withObject:days];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code that I want to make point-free; (\k t -> chr
Hi can you help me with this?? I have this code and i want
I have this html code that i want to edit with jQuery. Here is
I have this code in my controller and want to test this code line
I have this code , and I want to run Log.d every 1000 milis
I want to draw image in place where I click. i have this code:
i have this javascript code to which i want to add the jquery fade-in
I have this Java code, and I want to do the same thing in
I have created this Fiddle with this code: This is my problem I want
I want to force the download of an image. I have found this code:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.