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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:16:50+00:00 2026-06-03T20:16:50+00:00

I have an Model Class. When I call a the method setter, I set

  • 0

I have an Model Class. When I call a the method “setter”, I set some String values to the attributes of my object. After the attributes are set, the method returns the new Object which is stored in the NSMutableArray *eintraegeSortiert.

Now, I need a new Object. I think I have to remove the pointer and set it again. If I don’t remove the pointer, all the objects stored in the mutable array will change too and I have stored the same object a 100 times in that mutable array. I have tried in multiple ways, without getting it right. What am I doing wrong? My code:

NSMutableArray *eintraegeSortiert = [NSMutableArray array];
for (int i = 0; i < ([mArray count] / 11) ; i++) {
        Vertretung *vertretung = [[Vertretung alloc] init];
        [eintraegeSortiert addObject:[self setter:mArray :vertretung]];
    }
  • 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-03T20:16:51+00:00Added an answer on June 3, 2026 at 8:16 pm

    I think you’re not really understanding how the code you’ve written works. Let’s take a look at it:

    NSMutableArray *eintraegeSortiert = [NSMutableArray array];
    for (int i = 0; i < ([mArray count] / 11) ; i++) {
        Vertretung *vertretung = [[Vertretung alloc] init];
        [eintraegeSortiert addObject:[self setter:mArray :vertretung]];
    }
    

    So step by step:

    NSMutableArray *eintraegeSortiert = [NSMutableArray array];
    

    Creates a new mutable array and assigns it to eintraegeSortiert

    for (int i = 0; i < ([mArray count] / 11) ; i++) {
    

    We’re going to loop [mArray count] / 11 times.

    Vertretung *vertretung = [[Vertretung alloc] init];
    [eintraegeSortiert addObject:[self setter:mArray :vertretung]];
    

    Now, this is creating a variable within the current scope called vertretung. You call alloc/init. That will return a pointer to a new Vertretung object. For example this might be at memory location 0x12345678. Then you add that to the array.

    Then we get to the end of the current scope and loop back around the for-loop. That means the variable vertretung goes out of scope.

    Then when you loop around again, that same code runs again and again. But now the alloc/init will create an entirely new Vertretung object (maybe pointing to memory location 0xabcdef00 and add that to the array.

    So no, it’s not the same object being added to the array multiple times.

    Not sure what’s going on in setter:: – maybe post that as well if you’re still having issues.

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

Sidebar

Related Questions

I have model: [Validator(typeof(RegisterValidator))] public class RegisterModel { public string Name { get; set;
I have a model class with getter and setter methods, and the occasional static
My program class has: Application.Run(new Form1()); in form1 class I have: model = new
I have this class public class Model { private String a; private String b;
I have a view model public class PersonsViewmodel { public string FirstName { get;
I have jquery with class= modal i want to call that class when page
I have model public class UploadOptionModel { public UploadOptionModel() { OutputFormat = outputFormatList.Select(i =>
I have a model: class Example(models.Model): unique_hash = models.CharField(max_length=32,unique=True) content = models.FileField(upload_to='source',blank=True,verbose_name=HTML Content File)
I have a model class like this: class Note(models.Model): author = models.ForeignKey(User, related_name='notes') content
I have a model class that uses a custom validator as shown in following

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.