Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSArray add objects from other array

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?

like image 555
Matrosov Oleksandr Avatar asked Mar 29 '13 13:03

Matrosov Oleksandr


2 Answers

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]; 
like image 84
Monolo Avatar answered Oct 16 '22 19:10

Monolo


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
)
like image 6
Balu Avatar answered Oct 16 '22 19:10

Balu