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

  • Home
  • SEARCH
  • 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 8419551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:38:43+00:00 2026-06-10T02:38:43+00:00

I have a object from a class that is being copied to a NSMutableArray.

  • 0

I have a object from a class that is being copied to a NSMutableArray. I do that 5 times. However, whenever I try to retrieve the objects from that array they are all the same.

Here’s the sample code:

[myProperty setAddress:@"Av. dos Estados, 70."]; 
[myProperty setPropType:casaRua];
[myProperty setRentalPrice:1430.0];
[propertiesArray addObject:myProperty];

myProperty = [propertiesArray objectAtIndex:0];
NSLog(@"Price 0  %.2f\n", [myProperty rentalPrice]); //In this I got 1430.0

[myProperty setAddress:@"Av. das Nações, 10. Ap: 103."];
[myProperty setPropType:apto];
[myProperty setRentalPrice:450.0];
[propertiesArray addObject:myProperty];

myProperty = [propertiesArray objectAtIndex:0];//indexPath.row];
NSLog(@"Price 0  %.2f\n", [myProperty rentalPrice]); **//In this I got 450.0???**

myP = [propertiesArray objectAtIndex:1];//indexPath.row];
NSLog(@"Price 1  %.2f\n", [myP rentalPrice]); //In this I got 450.0

What am I doing wrong? It seems the array was overwritten with the addObject

  • 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-10T02:38:45+00:00Added an answer on June 10, 2026 at 2:38 am

    You’re re-modifying the same “property” object over and over again.

    You need to either copy it or instantiate a new one each time before modifying it, after adding the previous object.

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

Sidebar

Related Questions

I have an object from a NSObject class that I call brand and has
Example: I have an class that inherits from UIImageView. An object creates an instance
I have an Employee class object that I am calling from my Login.aspx page's
Suppose that we have previously instantiated three objects A, B, C from class D
I have a number of objects, all from the same class(ColorNum) Each object has
Suppose we have a class. We create an object from the class and when
I have this object: class a { public string Application; public DateTime From, To;
I have a pymzml.run.Reader class from the pymzml package. This is a generator object,
Let's say I have created two objects from class foo and now want to
Have a bit of confusion here. I added a few objects from a class

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.