Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mycompuser

macrumors member
Original poster
May 8, 2012
37
0
I am in the process of developing an datastore for my iOS app.

I have written an datastore which is an wrapper around NSMutableArray (say method "addObjectToDataStore" used to add data to the datastore).

I use the datastore throughout the various classes in my app to collect data (key/value pair) which I save onto it using static method exposed by the datastore class. Archiving of data on app exit and unarchiving of datacollector data is done my main appdelegate class.

This data from the datastore I read periodically and use for reporting purpose.

I'll have to trim/remove outdated/unused/stale data periodically (say once a day), so that the datastore size does not bloat.

My questing is with respect to the trimming of datastore data.
Whose responsibility is it to trim the data? I plan to expose an method "trim" in datastore class which might accept the trimming criteria(say max file size) and accordingly trim the data.

But not sure if that violates the "Single responsibility principle" for datastore class.
And who should have the responsibility of calling this "trim" method?

Should I call the "trim" method form the main appdelegate class or should I call the "trim" method from within "addObjectToDataStore" method of the datastore class such that when the criteria is satisfied, it would trim the data?
 
You might want to expose the trim method but best is if the datastore class does the trimming itself in response to whatever criteria to set for when to do the trimming. Your datastore class could set a timer that runs once per day so it gets called back when it needs to do this. It could register for various UIApplication life cycle events so that trimming happens when the app is going into the background. Consider that the trim operation might take some time so you may not want to do it as part of a request to add an object (but maybe you do).
 
Hi,

Thanks for the reply. I think your approach is the best.

Have implemented it as per the same where the method to trim is called from within the datastore class when the criteria is met.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.