I try to copy items from NSMutableArray to another.
I add items in my two first MutableArray (storiesRSS1
and storiesRSS2
):
[item setObject:currentTitle forKey:@"title"];
[item setObject:currentLink forKey:@"link"];
[item setObject:currentSummary forKey:@"summary"];
[item setObject:currentDate forKey:@"date"];
[item setObject:currentImage forKey:@"image"];
[item setObject:currentMovie forKey:@"movie"];
[storiesRSS1 addObject:[item copy]];
[item setObject:currentTitle forKey:@"title"];
[item setObject:currentLink forKey:@"link"];
[item setObject:currentSummary forKey:@"summary"];
[item setObject:currentDate forKey:@"date"];
[item setObject:currentImage forKey:@"image"];
[item setObject:currentMovie forKey:@"movie"];
[storiesRSS2 addObject:[item copy]];
For these two arrays it work.
After that I want to mix both in a third array (stories
).
int i=0;
int nbElement=[storiesRSS1 count]+[storiesRSS2 count];
while (i<nbElement) {
if (i<[tempArrayTed count]) {
[stories addObject:[storiesRSS1 objectAtIndex:i]];
}
if (i<[tempArrayYoutube count]) {
[stories addObject:[storiesRSS2 objectAtIndex:i]];
}
i++;
}
But when I try to show each items, it's always null
!
Could you help me, thanks.
NSMutableArray
has an addObjectsFromArray
: method that you might find useful.
[stories addObjectsFromArray:storiesRSS1];
[stories addObjectsFromArray: storiesRSS2];
On a side note, you're leaking memory when you do:
[storiesRSS1/2 addObject:[item copy]];
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