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?

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

4 Comments

Although a mutable array most likely fits better, sending messages to nil is fine in this case - see e.g. here.
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.
i set to nil, it doesn't work, use removeALlobjects and it works.
Thanks, exactly what I needed to do a table refresh.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.