0


I have searched the internet quite a while concerning this problem but didn't find anything related. So I have a simple question: Is it by any means possible to create a Mutable Array in Objective C by using a NSString Variable to name it?

To be more clear a code example (which doesn't work this way):

NSString* someString = @"RandomWord";

NSMutableArray* (someString) = [[NSMutableArray alloc] init];

Any help would be appreciated. If this does not work the way I intend to do it, it would be nice to know another way to dynamically create Arrays with reasonable, retrievable names.

Best Regards,
J


UPDATE:
I have an NSMutableDictionary in which I intend to save multiple NSMutableArray with URLs. The user can name the keys in the Dictionary himself.
For example: The user creates a category named "Animals" and stores multiple URLs in that category. So what I want to achieve is to save the NSMutableArray filled with the URLs for the key "Animals" in the NSMutableDictionary.
I originally thought about just using one NSMutableArray but as I learned the copies of the Array in the NSMutableDictionary are only shallow, so each time I filled the array with something new and stored it the old values were lost in my NSMutableDictionary. But since the User creates as many categories as he wants and also names them how he wants to I need to somehow create arrays that I can reasonably retrieve and add as content to the NSMutableDictionary.
I know this sounds kind of confusing but I hope I made my goal somehow clear.
If there are any questions please ask!

3
  • Tell us what you want to achieve. Commented Sep 21, 2014 at 11:48
  • please see edited question for details Commented Sep 21, 2014 at 12:02
  • Really I'd suggest just using a database, for something like this. It's very easy. So, icodeblog.com/2008/08/19/… Commented Sep 21, 2014 at 12:37

1 Answer 1

1

No you can't. You can, however, use an NSMutableDictionary, to store the instances.

An example:

NSMutableDictionary *dict = [NSMutableDictionary dictionary];
NSString *someString = @"RandomWord";
[dict setObject:[NSMutableArray array] forKey:someString];

Then to use later:

[[dict objectForKey:someString] doSomethingToTheArray];
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much for this answer! I think with this input I can find a way to solve my problem!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.