I have an array like this:
array: ( ( "http://aaa/product/8_1371121323.png", "http://aaa/product/14_1371123271.png" ), ( "http://aaa/product/9_1371121377.png" ) )
and I have to create another array from that one like this
array: ( "http://aaa/product/8_1371121323.png", "http://aaa/product/14_1371123271.png", "http://aaa/product/9_1371121377.png" )
How can I do that? Is it possible to combine all the objects and separate them using some string?
You can reverse a NSArray by writing your own loop iterating from the end towards the beginning and using a second array to add the items in reverse order. Or you can simply use - (NSEnumerator *)reverseObjectEnumerator from the NSArray class.
arrays can't contain nil.
NSArray creates static arrays, and NSMutableArray creates dynamic arrays. You can use arrays when you need an ordered collection of objects. NSArray is “toll-free bridged” with its Core Foundation counterpart, CFArrayRef . See Toll-Free Bridging for more information on toll-free bridging.
The answer is yes, the order of the elements of an array will be maintained - because an array is an ordered collection of items, just like a string is an ordered sequence of characters...
It can be done in a single line if you like key-value coding (KVC). The @unionOfArrays
collection operator does exactly what you are looking for.
You may have encountered KVC before in predicates, bindings and similar places, but it can also be called in normal Objective-C code like this:
NSArray *flatArray = [array valueForKeyPath: @"@unionOfArrays.self"];
There are other collection operators in KVC, all prefixed with an @
sign, as discussed here.
Sample Code :
NSMutableArray *mainArray = [[NSMutableArray alloc] init]; for (int i = 0; i < bigArray.count ; i++) { [mainArray addObjectsFromArray:[bigArray objectAtIndex:i]]; } NSLog(@"mainArray :: %@",mainArray);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With