6

I have three NSArray objects. I need to add all objects for this array to NSArray that is called allMyObjects.

Have NSArray standard solution to make it for example via initialization method or do I need make custom method to retrieve all objects from other arrays and put all retrieved objects to my allMyObjects array?

1
  • 1
    NSMutableArray has an -addObjectsFromArray: method. Commented Mar 29, 2013 at 13:42

4 Answers 4

26

Don't know if this counts as a sufficiently simple solution to your problem, but this is the straight forward way to do it (as alluded to by other answerers, too):

NSMutableArray *allMyObjects = [NSMutableArray arrayWithArray: array1]; 
[allMyObjects addObjectsFromArray: array2]; 
[allMyObjects addObjectsFromArray: array3]; 
Sign up to request clarification or add additional context in comments.

2 Comments

This is the method I tried to find. ty. But does it initialize array?
@GxocT not sure exactly what you are asking, but the arrayWithArray: method is a convenience constructor that allocates and initializes the array in one call.
6

once see this one ,

NSArray *newArray=[[NSArray alloc]initWithObjects:@"hi",@"how",@"are",@"you",nil];
    NSArray *newArray1=[[NSArray alloc]initWithObjects:@"hello",nil];
    NSArray *newArray2=[[NSArray alloc]initWithObjects:newArray,newArray1,nil];
    NSString *str=[newArray2 componentsJoinedByString:@","];
    NSCharacterSet *doNotWant = [NSCharacterSet characterSetWithCharactersInString:@"()\n "];
    str = [[str componentsSeparatedByCharactersInSet:doNotWant] componentsJoinedByString: @""];
     NSArray *resultArray=[str componentsSeparatedByString:@","];
    NSLog(@"%@",resultArray);

O/P:-

(
    hi,
    how,
    are,
    you,
    hello
)

1 Comment

Probably a better way to do it than I suggested, while keeping the order correct. +1
4

You can call addObjectsFromArray: method on your allMyObjects array.

1 Comment

...provided that it's mutable.
0

Here am adding code for store and get datas from array to array.

To store array to array

NSMutableArray rowOneRoundData = [NSMutableArray arrayWithObjects: @"45",@"29",@"12",nil];
 NSMutableArray   rowTwoRoundData = [NSMutableArray arrayWithObjects: @"41",@"45",@"45",nil];
   NSMutableArray rowThreeRoundData = [NSMutableArray arrayWithObjects: @"12",@"45",@"22",nil];
   NSMutableArray rowFourRoundData = [NSMutableArray arrayWithObjects: @"45",@"12",@"61",nil];
   NSMutableArray rowFiveRoundData = [NSMutableArray arrayWithObjects: @"12",@"14",@"14",nil];
   NSMutableArray rowSixRoundData = [NSMutableArray arrayWithObjects: @"12",@"12",@"12",nil];
   NSMutableArray rowSevenRoundData = [NSMutableArray arrayWithObjects: @"12",@"36",@"83",nil];
   NSMutableArray rowEightRoundData = [NSMutableArray arrayWithObjects: @"37",@"57",@"45",nil];
   NSMutableArray rowNineRoundData = [NSMutableArray arrayWithObjects: @"12",@"93",@"83",nil];
   NSMutableArray rowTenRoundData = [NSMutableArray arrayWithObjects: @"16",@"16",@"16",nil];
   NSArray circleArray = [[NSArray alloc]initWithObjects:rowOneRoundData,rowTwoRoundData,rowThreeRoundData,rowFourRoundData,rowFiveRoundData,rowSixRoundData,rowSevenRoundData,rowEightRoundData,rowNineRoundData,rowTenRoundData, nil];

Get data from Circle Array

for (int i= 0; i<10;i++)
{
NSArray *retriveArrar = [[circleArray objectAtIndex:i] mutableCopy];
}

Comments

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.