NSArray adds objects from another array

I have three NSArray . I need to add all the objects for this array to an NSArray called allMyObjects .

Do you have a standard NSArray solution, for example, using the initialization method, or do I need to make my own method to extract all objects from other arrays and put all the restored objects into the allMyObjects array?

+4
source share
4 answers

see it once

 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 / R: -

 ( hi, how, are, you, hello ) 
+6
source

I don’t know if this is considered a fairly simple solution to your problem, but this is a direct way to do this (as mentioned by other answering machines):

 NSMutableArray *allMyObjects = [NSMutableArray arrayWithArray: array1]; [allMyObjects addObjectsFromArray: array2]; [allMyObjects addObjectsFromArray: array3]; 
+21
source

You can call the addObjectsFromArray: method in your allMyObjects array.

+4
source

Here I add the code to store and get the data from the array to the array.

To save an array to an 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 a circle array

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

All Articles