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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:32:17+00:00 2026-06-03T23:32:17+00:00

Im trying to add an object to NSMutableArray it seems to get duplicated. @interface

  • 0

Im trying to add an object to NSMutableArray it seems to get duplicated.

@interface TestObject : NSObject {
    double a_actual;
    double a_target;
}
@property(assign) double a_actual;
@property(assign) double a_target;

Create some pointers:

NSMutableArray * myTestObjectArray;
TestObject * myTestObject;

Init them:

myTestObjectArray = [[NSMutableArray alloc] init];
myTestObject = [[TestObject alloc] init];

I add value to the object and add it to the array:

[myTestObject setA_actual:234];
[myJointDataArray insertObject:myTestObject];

I add different values to each object, but i do not necessarily fill all the variables out.
When i print each object out i have the same (last) value duplicated in all objects for some reason.

Printing the array shows that all objects are the same:

 Array: (
     "<TestObject: 0x6b9b400>",
     "<TestObject: 0x6b9b400>",
     "<TestObject: 0x6b9b400>",
     "<TestObject: 0x6b9b400>",
     "<TestObject: 0x6b9b400>",
     "<TestObject: 0x6b9b400>" )

Should i alloc a new object of TestObject everytime i want to work with a new?

  • 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-03T23:32:18+00:00Added an answer on June 3, 2026 at 11:32 pm

    Should i alloc a new object of TestObject everytime i want to work with a new?

    Yes. If you don’t allocate a new object, you’re just working with the same object over and over again. It appears you want multiple, distinct objects, so allocate a new instance for each one.

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

Sidebar

Related Questions

I'm trying to add objects to NSMutableArray (categoriasArray), but its not done by the
Trying to add a class object into a List using reflection, but when invoking
I am trying to add the datetime object of a person. Whenever the birth
I am trying to add time to a Date object in javascript but am
I'm trying to add a unittest attribute to an object in Python class Boy:
I have been trying to add to the Watch window a Java Date object
I was trying to add 200k messages to a core data object for a
I am getting errors when trying to add items to a NSMutableArray which is
I have a custom class MDRect that i am trying to add an NSMutableArray
@interface SimataDetailViewController () @property Simata *simata; @property (nonatomic, copy) NSMutableArray *simataList; @end @implementation SimataDetailViewController

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.