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?
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.
Use List. clear() method to empty an array.
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.
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".
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