I have multiple NSString Arrays that I would like to combine into a single array based on user preferences.
The arrays are created:
static const NSString *string1[] =
{...};
static const NSString *string2[] =
{...};
static NSMutableString *string3[] =
{
};
String3 is the holding array where all of the user’s choices are added. There are 8 different strings that could be toggled on or off, so a fair number of possible combinations. I’ve tried a number of things with no success. For example:
*string3=[string3 arrayByAddingObjectsInArray:string 2];
That gives warnings:
Instance method '-arrayByAddingObjectsInArry:' not found (return type defaults to 'id')
and
Receiver type 'NSMutableString **' is not 'id' or interface pointer, consider casting it to 'id'
Thanks for your help.
Your basic problem is that you’re confusing two different things called “arrays.” What you have there are C arrays — they’re not objects, so you can’t send messages (such as
arrayByAddingObjectsInArray:) to them. What you want is an NSArray.Declare them all as
NSArray *strings1, *strings2, *strings3, and then write some method to initialize them like so:You’ll want to make sure you manage your memory correctly here or you’ll leak like crazy. It’s usually better to have objects belong to some class, so you can use setters than manage memory for you, rather than store them in global or static variables.