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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:07:17+00:00 2026-06-12T06:07:17+00:00

I have a NSDictionary that contains objects and keys. The Keys hold a Name

  • 0

I have a NSDictionary that contains objects and keys. The Keys hold a Name and number. I would like to insert those objects into a NSMutableArray by using insertObject: atIndex: . Object being the name and the number is the index I would like to place the object in. I now know that NSMutableArrays are able to insert objects at index:6 if there is no 1-5 so how do I make this possible? Any suggestions are very appreciated!

Example Dictionary [dict objectForKey:@”array”]:

 preferences as whole (
        {
        Name = PowerDown;
        btnIndex = 3;
    },
        {
        Name = ClearCache;
        btnIndex = 5;
    },
        {
        Name = KillBGApps;
        btnIndex = 6;
    },
        {
        Name = InfoPanel;
        btnIndex = 2;
    },
        {
        Name = Lock;
        btnIndex = 4;
    },
        {
        Name = Reboot;
        btnIndex = 0;
    },
        {
        Name = Respring;
        btnIndex = 1;
    }
)

What I have so far but crashes when adding objects out of bounds of the array

-(void)loadArray{

 self.buttons = [NSMutableArray array];


    NSMutableArray *tempArray = [[NSMutableArray alloc] init];
    tempArray = [buttonsPrefs objectForKey:@"buttonsToOrder"];


    for(NSDictionary * dict in tempArray)
    {
        if (dict) {

            NSString *btnName = [dict objectForKey:@"Name"];

            NSString *btnIndex = [dict objectForKey:@"btnIndex"];
            NSUInteger index = [btnIndex integerValue];

            NSLog(@"Name = %@",btnName);
            NSLog(@"at index %i",index);

            [self.buttons insertObject: btnName atIndex: index];
        }


    }

}

EDIT: These values “indexes” for the names with change when a user moves the cell

- (void) tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath 
*)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
NSUInteger fromIndex = [fromIndexPath row];
NSUInteger toIndex = [toIndexPath row];
if (fromIndex == toIndex)
    return;
NSMutableDictionary *selectedButton = [[[_buttons objectAtIndex:fromIndex] retain] 
autorelease];
[_buttons removeObjectAtIndex:fromIndex];
[_buttons insertObject:selectedButton atIndex:toIndex];


//[buttonsPrefs setObject:_buttons forKey:@"buttonsToOrder"];
//[buttonsPrefs writeToFile:[self getFilePath] atomically: YES];


}
  • 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-12T06:07:18+00:00Added an answer on June 12, 2026 at 6:07 am

    Try to fill your target array with some dummy data according to yourDict count like this:

    for (int i=0, i<[yourDict count], ++i){
        [yourArray addObject:@"dummyData"];
    }
    

    And when you will need to insertObject do this:

    for(NSDictionary * dict in tempArray)
    {
        if (dict) {
    
            NSString *btnName = [dict objectForKey:@"Name"];
    
            NSString *btnIndex = [dict objectForKey:@"btnIndex"];
            NSUInteger index = [btnIndex integerValue];
    
            [yourArray insertObject:btnName atIndex:index];
            [yourArray removeObjectAtIndex:index+1];
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an NSArray which contains NSDictionary objects with keys that are NSNumber objects.
I have a BankAccount model class that contains data like account number, bank name,
I have a NSDictionary that contains multiple keys with the same name. Here is
I have a NSDictionary that contains data converted from json data, like {message_id:21} .
I have a single NSDictionary object which contains a large number of custom objects.
I have a class that contains an NSDictionary and periodically, I have a thread
The issue I'm running into is I have an NSMutableArray labeled: _podAllEntries, which contains
I have an NSDictionary that holds all the data: One title (not important for
I have a simple NSDictionary that I am trying to populate with data from
I have some NSDictionary objects stored in an NSArray called telephoneArray . I fetch

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.