I need to dynamically, at run time do the following with a NSMutableDictionary …
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?
Arrays are objects, and you add them to a dictionary the same way that you’d add any other object to a dictionary:
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:
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: