1

Can you store an Array ( that contains another two subarrays one being a string and another another array) into a single MutableArray object?

1
  • Can you be a little more specific with your question? There are several ways to interpret what you have asked. Commented Dec 9, 2008 at 3:21

3 Answers 3

3

Please read the documentation on NSArray. It can contain any number of arbitrary objects.

That said, without knowing more about what you're doing, I'd suggest you look at NSDictionary and its mutable subclass.

Sign up to request clarification or add additional context in comments.

Comments

3

Yes, you can store any type of object into one of the NSArray classes. The only difficulty is in conceptually dealing with how to access this data structure; complex nesting of arrays within arrays can be hard to manage and lead to bugs. Make sure your needs aren't better solved by another data structure, or a custom class.

Comments

0

Yes. You can use the following (enormous) line of code:

NSMutableArray * completeArray =
    [NSMutableArray arrayWithArray:
        [[myArray objectAtIndex:0] arrayByAddingObjectsFromArray:
            [myArray objectAtIndex:1]]];

edit: Assuming that myArray is defined as follows:


NSArray * stringArray = [NSArray arrayWithObjects:
                         @"one", @"two", @"three", nil];
NSArray * otherArray = [NSArray arrayWithObjects:
                        someObj, otherObj, thirdObj, nil];
NSArray * myArray = [NSArray arrayWithObjects:
                     stringArray, otherArray, nil];

The line of code I posted above will give you one big NSMutableArray which contains:

@"one, @"two", @"three", someObj, otherObj, thirdObj

Comments

Your Answer

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