1

In my iOS application, I want to store some messages that I obtain from my remote server. However, instead of storing these messages forever, I want to purge, once I have a N number of messages; i.e., if my N is configured to be 10, I want to store 10 messages and on the arrival of the 11th message, I want to delete the 1st message.

Is there a standard way to do this in iOS ? I am yet to write the code to saving the messages, so choosing any method of saving is fine for me.

Bernhard Barker
  • 54,589
  • 14
  • 104
  • 138
Sankar
  • 6,192
  • 12
  • 65
  • 89

2 Answers2

1

I dont think there is a straight fwd way.

The way I would do is have a table using SQLLite. Have 2 columns id(int, autoincrement), value(String). When inserting, if max(id) >=10 delete row with min(id) and insert the new value.

Ofcourse, this woud fail after it reached MAX_INT_VALUE. So if you thing you would never get to this value you are good.

Vijay
  • 31
  • 1
  • 5
1

Store your messages in a file. After you get the message read your file's messages to an NSMutableArray, replace the most old message with new one and overwrite your file with new array data.

Maksim
  • 2,054
  • 3
  • 17
  • 33