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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:35:09+00:00 2026-06-02T04:35:09+00:00

I need to dynamically, at run time do the following with a NSMutableDictionary …

  • 0

I need to dynamically, at run time do the following with a NSMutableDictionary …

  • create (perhaps thousands) of arrays that are added to the dictionary. This will be done inside a loop and the number of arrays needed will be unknown as they are driven off a plist of words.
  • create (thousands) of strings for each array. Again, data driven, the number of strings is known only at runtime.
  • Use the key to represent some character pattern for the particular array (ex: ‘m-m-‘ means the array contains strings with two m’s at the 2nd & 4th location.)
  • Use the value to represent the count of strings that match the pattern (ex:200 strings are of ‘-m-m’ pattern), and use the array to have the actual 200 strings.

    So once implemented, the dictionary will contain a count/value of each pattern/key and the actual strings that match that pattern.

    I need help with the proper syntax for creating dictionary and adding arrays dynamically, and incrementing the count/value, and I suppose appending/inserting the strings but that part I think I am good with.

    related post: NSMutableArray or NSMutableDictionary : which is best for this scenario?

    • 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-02T04:35:11+00:00Added an answer on June 2, 2026 at 4:35 am

      I need help with the proper syntax for creating dictionary and adding
      arrays dynamically, and incrementing the count/value,

      Arrays are objects, and you add them to a dictionary the same way that you’d add any other object to a dictionary:

      [someDictionary setObject:theArray forKey:theKey];
      

      I’m not clear on what you mean about “incrementing the count/value”. A dictionary knows how many key/value pairs it contains — no need to increment anything. Same goes for arrays.

      So it sounds like your code is going to go something like:

      NSMutableDictionary *dict;
      for (NSString *word in wordlist) {
          @autorelease {
              NSMutableArray *wordStrings = [NSMutableArray array];
              while (/*some condition based on word*/) {
                  NSString *newString = [NSString stringWithFormat:...];
                  [wordStrings addObject:newString];
              }
              [dict setObject:wordStrings forKey:word];
          }
      }
      

      I’m sure that’s not quite right — I have no idea what you’re really trying to do, but the code above shows how you’d generate some number of arrays and add them to a dictionary. The rest is up to you.

      Looking at your edit, I think you may be a little confused about what’s stored in a dictionary. A dictionary is just a set of key/value pairs. In this case, the values are the arrays that you add, and the keys are the pattern strings. There’s no space for an extra “value” for each key that stores a count. You could have two entries for each pattern using some convention for the keys like pattern and *pattern_count*. There’s no need to do that, though… the array stored for each pattern can easily tell you how many objects it contains:

      NSArray *wordList = [dictionary objectForKey:pattern];
      int count = [wordlist count];
      
      • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
        • Report

    Sidebar

    Related Questions

    I need to dynamically create textbox. This is my code, but with this I
    We need to dynamically create (i.e. during runtime, via code-behind) UserControls and position them
    I need to dynamically generate radio or checkbox by jQuery. I use the following
    I have a GridView that I need to dynamically add TemplateField elements to. My
    I have a table of data that I need to dynamically add a column
    I need to dynamically bind properties of components created at runtime. In this particular
    Is there a way to debug a function that is defined dynamically in run
    I need to dynamically allocate 1-D and 2-D arrays whose sizes are given at
    I need to be able to dynamically modify an NSMenu hierarchy each time it
    I am creating the columns of a datagrid dynamically at run time and I

    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.