Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set array empty

I have a clear history button which clears the data in plist. Now, loading is fine; I load it to an array.

Can I just use:

self.dataClear = NULL;

and save back the array to plist to clear it? So that I can use

if([self.dataClear count] == 0)//if plist is empty

to check?

like image 627
Stefan Avatar asked Aug 22 '10 18:08

Stefan


People also ask

How do you condition an empty array?

To check if an array is empty or not, you can use the . length property. The length property sets or returns the number of elements in an array. By knowing the number of elements in the array, you can tell if it is empty or not.

How do you assign an empty array in Java?

Use List. clear() method to empty an array.

How would you empty an array in JavaScript?

In the above program, the splice() method is used to remove all the elements of an array. In the splice() method, The first argument is the index of an array to start removing an item from. The second argument is the number of elements that you want to remove from the index element.


1 Answers

You'd probably be better off using a NSMutableArray and calling removeAllObjects on that instead of NULLing it out; otherwise, there won't be any object there to respond to your count message, since there's a conceptual difference between "empty array" and "no array at all".

like image 160
ig2r Avatar answered Nov 15 '22 16:11

ig2r