NSMutableArray adds NSMutableArray
I am trying to set the content of my allArticlesArray and then add an array with additional objects. Here's a snippet of my code to do it:
[self.allArticlesArray setArray:newsArray];
[self.allArticlesArray addObjectsFromArray:sportsArray];
newsArray and sportsArray are non-zero (each has five elements), but after running this code, allArticlesArray is null. I am using ARC. What am I doing wrong? Thank you!
+3
source to share
2 answers
I assume you forgot to initialize allArticleArray
self.allArticlesArray = [NSMutableArray array];
[self.allArticlesArray setArray:newsArray];
[self.allArticlesArray addObjectsFromArray:sportsArray];
or a little concise:
self.allArticlesArray = [newsArray mutableCopy];
[self.allArticlesArray addObjectsFromArray:sportsArray];
+5
source to share