views:

40

answers:

1

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?

A: 

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".

ig2r
Although a mutable array most likely fits better, sending messages to `nil` is fine in this case - see e.g. [here](http://stackoverflow.com/questions/156395/sending-a-message-to-nil).
Georg Fritzsche
Indeed, though I wanted to stress that distinction between `nil` and empty, since I consider `count` working as expected here somewhat of a fringe case. Nevertheless, your point is correct.
ig2r
i set to nil, it doesn't work, use removeALlobjects and it works.
Stefan