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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:15:42+00:00 2026-06-01T14:15:42+00:00

I’m quite new in Objective-c leaning so if my question is too stupid, please

  • 0

I’m quite new in Objective-c leaning so if my question is too stupid, please don’t kill me ^^

There’s my problem :

*Architecture : *

I have an objet : Guest with a property : listOfPricePaidByGuest
This property is an array of NSNumber.
All the guest are in this NSMutableArray : currentListOfBeneficiaries

*Situation : *

I have a UIViewController where i allow the user to modify the values in listOfPricePaidByGuest

I want to allow the user to cancel all the modification.
So when the view is loaded, i’m copying the guest in a new mutableArray : tempListOfBeneficiaries (i’ve already implemented the NSMutableCoying delegate and checked that the two objects have a different memory adress).

When the user click on Save, i’m juste removing the view, beacause all the modification are done.

When the user click on Cancel, i’m juste using setArray method to the original listOfPricePaidByGuest.

The fact is that all NSnumber in my tempArray are also modificated and i don’t understand why…
I’ve tried everything i could…

*Question : *

Does anyone know a method to get these values unchanged ?

*Some code : *

Copying to tempArray

    for (Guest *newGuest in self.currentGrocery.listOfBeneficiaries)
    {
        // Copying original guest
        Guest *copyGuest = [newGuest mutableCopy];

        for (NSNumber *aNumber in newGuest.listOfPricePaidByGuest)
        {
            int index = [newGuest.listOfPricePaidByGuest indexOfObject:aNumber];

            // Copying NSNumber in newGuest.listOfPricePaidByGuest
            NSNumber *newNumber = [aNumber copy];

            // Replace current object
            [copyGuest.listOfPricePaidByGuest replaceObjectAtIndex:index withObject:newNumber];

            // Releasing current copied number
            [newNumber release];
        }

        // Add it to tempArray
        [self.tempListOfBeneficiaries addObject:copyGuest];

        // Releasing current copiedGuest
        [copyGuest release];
    }

* Implementation for NSMutableCopying delegate *

    -(id)mutableCopyWithZone:(NSZone *)zone
    {
        Guest *guestCopy = [[Guest allocWithZone: zone] init];
        [guestCopy setListOfGrocery:self.listOfGrocery];
        [guestCopy setListOfPricePaidByGuest:self.listOfPricePaidByGuest];

        [guestCopy setGuestName:self.guestName];
        [guestCopy setGuestEmail:self.guestEmail];
        [guestCopy setGuestNickname:self.guestNickname];
        [guestCopy setGuestPhone:self.guestPhone];

        [guestCopy setTotalGuestDepense:self.totalGuestDepense];
        [guestCopy setTotalGuestDepenseToPayAfterReeq:self.totalGuestDepenseToPayAfterReeq];

        [guestCopy setIsComming:self.isComming];
        [guestCopy setIsSend:self.isSend];

        return guestCopy;
    }

PS : Sorry for the english… It’s quite late and… Well i’m french so it explains everything 😛

Thanks for helping 🙂

  • 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-01T14:15:43+00:00Added an answer on June 1, 2026 at 2:15 pm

    The problem is in the array, not the NSNumbers. At the moment, you always have one array, never two. In [Guest mutableCopyWithZone:], you must copy the listOfGrocery and listOfPricePaidByGuest arrays:

    [guestCopy setListOfGrocery:[self.listOfGrocery mutableCopy]];
    [guestCopy setListOfPricePaidByGuest:[self.listOfPricePaidByGuest mutableCopy]];
    

    It might be better still to have setListOfGrocery and setListOfPricePaidByGuest carry out this copying step, unless there are times when you’ll need to retain the input array. If you’re defining these with @property, just use replace assign or retain with copy.

    Also, is this using Automatic Reference Counting or Garbage Collection? If not, the copies need to be released at some point.

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

Sidebar

Related Questions

I don't have much knowledge about the IPv6 protocol, so sorry if the question
This could be a duplicate question, but I have no idea what search terms
I have been unable to fix a problem with Java Unicode and encoding. The
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
I have a small JavaScript validation script that validates inputs based on Regex. I
this is what i have right now Drawing an RSS feed into the php,

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.