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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:22:20+00:00 2026-06-08T09:22:20+00:00

I have a function in which an NSMutableDictionary is being populated by the values

  • 0

I have a function in which an NSMutableDictionary is being populated by the values of an NSMutableArray. This NSMutableArray stores the CGPoints based on the movement of the finger. When touchesEnded is called, the values inside the NSMutableArray is “transferred” into the NSMutableDictionary, then it is emptied. I am doing this just to keep track on the finger movements (and for other purposes).

The problem here is that when the NSMutableArray is emptied, the NSMutableDictionary is emptied as well.

This is my code:

[pointDict setObject:pointArr forKey:[NSNumber numberWithInt:i]];
//When I check if the pointDict is not empty, it works fine.
[pointArr removeAllObjects];
//Now when I check if the pointDict is not empty, it returns nothing.

Can anyone tell me why is this happening? What’s the problem with the code?

  • 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-08T09:22:22+00:00Added an answer on June 8, 2026 at 9:22 am

    When you call setObject:forKey: you are just passing along a pointer to the same object that pointArr is pointing to. So when you tell the array to removeAllObjects, all the points are gone, because there is only one array.

    You need to make a copy before you store it. Assuming you are using ARC, and that you don’t need to modify the array after you put it in the pointDict, you can do this:

    [pointDict setObject:[pointArr copy] forKey:[NSNumber numberWithInt:i]];
    

    If you need to keep the array mutable, you can use mutableCopy instead.

    If you’re not using ARC, you will need to use release or autorelease to release your claim on the the copied array after you put it in the dictionary (since copy creates a new object, just like alloc, you are responsible for releasing it).

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

Sidebar

Related Questions

I have a function which looks something like this, it returns a noncopyable class
I have a function which runs based on a setInterval() call. It looks like
I have a function which looks like this. function loadbottom(){ $(#uploadsegment).load(bottompart.php?id=<?php echo $_GET['id'] ?>&page=<?php
I have a function which creates a SELECT statement with a WHERE clause. This
I have this function which writes content to a text file: function write($text){ fwrite($this->fp,
i have a function which retrieves values from a webservice , then loops through
I have function which bind draggable functionality to newly added div. Something like this:
i have function which is something like this function multiple_delete($entity1,$entity2,$entity2) { $query = SELECT
I have a function which receives a string parameter, I need to convert this
I have this function which gets executed when a link is clicked. But there

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.