9

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?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Stefan
  • 235
  • 1
  • 5
  • 18

1 Answers1

19

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
  • 2,396
  • 1
  • 16
  • 17
  • 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 Aug 22 '10 at 18:34
  • 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 Aug 22 '10 at 18:37
  • 1
    i set to nil, it doesn't work, use removeALlobjects and it works. – Stefan Aug 22 '10 at 19:20
  • Thanks, exactly what I needed to do a table refresh. – James Apr 26 '12 at 16:09