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 8009073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:20:27+00:00 2026-06-04T18:20:27+00:00

working with a basic objective c example here, tried to use replaceObjectAtIndex for an

  • 0

working with a basic objective c example here, tried to use replaceObjectAtIndex for an array and it doesn’t seem to be working.

my code:

 NSMutableArray *myArray=[NSMutableArray array];
    [myArray addObject:@"First string"];
    [myArray addObject:@"Second string"];
    [myArray addObject:@"Third string"];

    NSString *newElement=[myArray objectAtIndex:1];
    NSLog(@"New object at index 1 BEFORE is %@", newElement);
    [myArray replaceObjectAtIndex:1 withObject:@"Hello"];
    NSLog(@"New object at index 1 AFTER is %@", newElement);

theoretically the output for newElement should now display “Hello”, but it’s still displaying “Second String”

output:

2012-05-30 11:21:16.638 cocoa lab[753:403] New object at index 1 BEFORE is Second string
2012-05-30 11:21:16.641 cocoa lab[753:403] New object at index 1 AFTER is Second string

please advise

thank you

  • 1 1 Answer
  • 0 Views
  • 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-06-04T18:20:29+00:00Added an answer on June 4, 2026 at 6:20 pm

    You need to get the new value from the array after replacing it

    // ...
    [myArray replaceObjectAtIndex:1 withObject:@"Hello"];
    
    /* ADD THIS */
    newElement=[myArray objectAtIndex:1];
    
    NSLog(@"New object at index 1 AFTER is %@", newElement);
    

    At the moment you fetch the original string, replace the array’s object, and print out the original string again.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a basic modal example in which the modal would follow the
As the title states, I'm looking for a basic (working) tutorial of Java code
For this example, I am working with objective-c, but answers from the broader C/C++
I am working on a basic game in javascript. I don't use jQuery. The
I am trying to use some C code in Unity3D pro. My basic approach
I have a small, basic working example of using WCF to get two applications
I have a service, as follows: The most basic (working) CherryPy 3.1 Windows service
Basic summary: Working on a game that generates a 15x15 grid for the player
I am working on a basic hello world application that will open a txt
I'm working on a basic google applications based system. Like I earlier defined I'm

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.