3

I am trying to set the contents of my allArticlesArray, and then append the array with additional objects. Here is a snippet from my code to do so:

[self.allArticlesArray setArray:newsArray];
[self.allArticlesArray addObjectsFromArray:sportsArray];

newsArray and sportsArray are non-null (they each have five items), however, after this code runs, allArticlesArray is null. I am using ARC. What am I doing wrong? Thanks!

2 Answers 2

5

I assume you forgot to initialize allArticleArray

self.allArticlesArray = [NSMutableArray array];

[self.allArticlesArray setArray:newsArray];
[self.allArticlesArray addObjectsFromArray:sportsArray];

or a bit concise:

self.allArticlesArray  = [newsArray mutableCopy];
[self.allArticlesArray addObjectsFromArray:sportsArray];
Sign up to request clarification or add additional context in comments.

1 Comment

it is always causing confusion to new objective-c programmer, that sending a message to nil is not an error or raises an exception.
1

Use this

self.allArticlesArray=[NSMutableArray arrayWithArray:setArray];
[self.allArticlesArray addObjectsFromArray:sportsArray];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.