ios NSArray 从其他数组添加对象
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15704428/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
NSArray add objects from other array
提问by Matrosov Alexander
I have three NSArray
objects. I need to add all objects for this array to NSArray
that is called allMyObjects.
我有三个NSArray
对象。我需要将此数组的所有对象添加到NSArray
名为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 allMyObjectsarray?
有NSArray
标准的解决方案,例如通过初始化方法来实现它,还是我需要自定义方法来从其他数组中检索所有对象并将所有检索到的对象放入我的allMyObjects数组?
回答by Monolo
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];
回答by Balu
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
)
回答by Levi
You can call addObjectsFromArray:
method on your allMyObjects
array.
您可以addObjectsFromArray:
在allMyObjects
数组上调用方法。
回答by abdul sathar
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];
}