Reputation: 2670
I know how I would achieve this using NSMutableArray, but whats the correct way of emptying a whole array of class NSArray. I need to do this because I need to reload a tableView. Im using ARC.
Upvotes: 0
Views: 119
Reputation: 1097
NSArray *yourArray = [ whatever objects you have ]
//to empty this array
yourArray = [NSArray array];
Upvotes: 1
Reputation: 8345
NSArray
is an immutable (unchangeable) class so there is no way to remove elements from the array. Basically, you will have to throw the array away and replace it with a new NSArray
. Alternatively, you could just use an NSMutableArray
.
Upvotes: 1
Reputation: 7633
You cant empty a non mutable NSArray, the best approach is to get a mutable copy of your array:
NSMutableArray *arr=[yourArr mutableCopy];
[arr removeAllObjects];
Upvotes: 0
Reputation: 7386
NSArray is an immutable type. You cannot alter it's contents after creation.
Either use an NSMutableArray or replace it with a new (empty) NSArray.
Upvotes: 4