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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:35:09+00:00 2026-05-22T20:35:09+00:00

There are lots of examples on this site about adding to NSMutableArray and I

  • 0

There are lots of examples on this site about adding to NSMutableArray and I have looked at many but I still don’t either understand (highly possible) or am missing something fundamental.

I am trying to add to an NSMutableArray via a for loop. I want to keep track of button x,y coordinate position using the button tag as key/index so I can change a button as a user clicks it. This is all without IB.

My init is as follow:

self.tmpXpos = [[NSMutableArray alloc] init];
self.tmpYpos = [[NSMutableArray alloc] init];

[self.tmpXpos insertObject:[NSNull null] atIndex:0];

[self.tmpYpos insertObject:[NSNull null] atIndex:0];
**I added these after reading about ‘creating’ the array and populating it with null.

In the loop:

NSUInteger btag = button.tag; //NSUInterger as per help

>>NSNumber *xNumber = [NSNumber numberWithInteger:[self xpos]]; // NSNumber as an Object wrapper
>>NSNumber *yNumber = [NSNumber numberWithInteger:[self ypos]];


>>[self.tmpXpos insertObject:xNumber atIndex:btag];
>>[self.tmpYpos insertObject:yNumber atIndex:btag];

NSLog(@”%d, %@, %@”,btag,xNumber,yNumber);

The log entries look ok:

2,64,0

3,128,0

etc for each button to be added to the screen.

During debugging – the tmpXpos and tmpYpos listed as ” 0 Objects ” under self.

I retrieve the information thusly:

NSUInteger tmpSt = [self.sTags integerValue];

NSNumber *tmpX = [self.tmpXpos objectAtIndex:tmpSt];

NSNumber *tmpY = [self.tmpYpos objectAtIndex:tmpSt];

int tmpPositionX = [tmpX intValue];

int tmpPositionY = [tmpY intValue];

NSLog(@”%d, %d”,tmpPositionX, tmpPositionY);

NSLog yields 0, 0

I do appreciate any guidance or questions you folks might have as this site’s ‘sanity checks’ have saved my bacon in the past.

I am ignoring memory leaks as of yet, but they are in the back of my mind. No worries there.
Ironically, I have a couple of other arrays that work just fine, but the exception is that they are not populated via a loop.

Lastly, the code works fine as the button at location 0,0 does change as per design, LOL, but not for any other location.

Thanks again!

Neil

  • 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-05-22T20:35:10+00:00Added an answer on May 22, 2026 at 8:35 pm

    I think your problem is that you are creating the NSNumbers with the method numberWithInteger, when an NSUInteger is actually an unsigned long. So try

    xNumber = [NSNumber numberWithUnsignedLong:[self xpos]];

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

Sidebar

Related Questions

There are lots of PHP articles about the subject so is this a PHP
There are lots of non-image-based CAPTCHA ideas floating around. But what about the old-fashioned
There are lots of IDEs for PHP development, but I'm curious about all the
There's lots of information about how cached execution plans in SQL Server eliminate much
I have heard that there is lots of interesting and useful WSGI middleware around.
This is a simplification of the issue (there are lots of ways of doing
For C++, there are lots of good unit test frameworks out there, but I
There is this site ... ... where they explain how to draw an antialiased
There are lots of web application frameworks available these days, for pretty much every
There are lots of questions on how to improve communication between teams. One way

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.