Question

I've developed a reading tracking app in Swift and for simplicity's sake I used arrays for my model. It stores some data about the books a user reads and a small image of the cover. I save them to disk periodically for persistence. Now I'm wondering as people use the app, at what point would it be wise to convert my model to using CoreData instead? And would you make that decision based on file size, or number of entries? I ran a test by increasing the number of entries and it seemed like everything worked fine until I started getting into hundreds of entries, at which point the UI started getting laggy. It would probably take a user a pretty long time (years?) to reach that point, but I'd rather know sooner not later if I'm going to have to make a switch.

I've tried searching around for some guidelines and haven't found anything helpful. Anybody with experience out there have any suggestions?

Was it helpful?

Solution

I don't think your UI got laggy because the application cannot process data arrays with hundreds of entries. 1000 strings with a length of, say, 100 characters cost around 100kB memory, that's less than all but the most basic images alone.

I suspect something else is happening, like a suboptimal reuse of UITableViewCells (or no reuse at all), or not releasing images when you don't need them anymore. Also, having to scroll through hundreds of entries is probably not what you want your users to do either.

There are many reasons to switch to CoreData or another ORM framework, and if you have big plans for your application it's best to start early instead of converting halfway through the project, but using arrays and storing them as property lists or even flat files still works for very simple apps, even if they contain hundreds or thousands of entries. It tends to get complicated when you store many different types of information (e.g. not only book covers but also detailed author information) and need to combine them; that's where the ORM frameworks will really prove their value.

Licensed under: CC-BY-SA with attribution
scroll top