Would you use Core Data for an iOS app with a social feed (think Facebook posts), where you sometimes have a need to persist those feed items?
-
We are building a mobile polling app, similar to the Twitter model where you view a feed of those you are following, and can also ask questions directly. So it makes sense to persist questions you asked (and their related objects, answer choices and responses), as you'll want to view those fairly often. At the same time, you can browse a (nearly) infinite list of questions from others, either from your feed or by exploring by hashtag, etc. Core Data (sqlite backed in this instance) is certainly a nice solution for the data I want to persist, and makes merging in any updates from the network nice as well. It also provides querying, relationships, and handy components like NSFRC. But I don't really want to store all those very temporary questions in sqlite. I suppose I could purge the database once and awhile on a low priority background task. Is this something where multiple persistent stores would be of use? Perhaps keeping most questions in a memory store, but copying important ones (asked, or incoming direct questions) into the sqlite? Edit: I suppose since a small subset of the data is being persisted, it's worth considering using NSCoding. But then I would think you need to be conscious of trimming that occasionally, so you don't end up storing far too much in memory after a lot of use. Really curious how this is handled.
-
Answer:
What I would do: Core Data I would be to use Core Data for the social feed. Core Data supplies such rich functionality with such a small footprint. It will be quite a long time before anyone reaches the end of their storage capacity on an iOS device. Most importantly, if the rest of your project is using Core Data, you're probably building infrastructure to support and abstract fetches, syncing, caching, observing etc etc. A concrete example: Using Core Data for a Feed On my most recent project: at Everest: http://www.everest.com, everything was an NSManagedObject. Users, Comments, Feed Items, Notification items, everything. We built a sync mechanism to communicate with the server and mapping rules to turn the server's JSON into consumable and manageable NSManagedObjects. A counter example: Rolling your own data layer specifically for a feed As a counter example, at Jawbone http://Jawbone.com/up in the early implementations, we used Core Data for everything except the social feed. That is, for the feed, we did exactly what you are counter proposing. We used a simple NSArray of NSDictionaries that we refetched from a cache. We lost all of the built in cache that Core Data supplies for a custom built caching mechanism. We lost all of the compile time type checking in relationships and attributes. We lost all of the infrastructure that we'd built off of querying, processing, and observing all in the sake of "simplicity". This all came down to an engineering discussion and decision that we (reluctantly) agreed on early and several of us regretted it every time we needed to deal with the feed. What I think you should do: Be Consistent My recommendation would be to use what you use throughout the app. If you use Core Data, continue using Core Data. If you use some other practice such as NSArray's, NSCoding, straight JSON or anything else, continue using that. Whatever your preference or experience level with Core Date, you've got a functioning code base and a long line of developers that will take over for you down the road. The least you could do is maintain some level of consistency so they have less they need to become familiar with.
Roderic Campbell at Quora Visit the source
Other answers
CoreData is an 80/20 thing. You'll get 80% or more of what you want effectively for free. It's not *that* hard to prune out old posts in a different NSManagedObjectContext. You'll get all the additional advantages that come with NSFetchedResultsController in your table view (I assume that's going to be somewhere) and having CoreData help manage the size of your object graph. The alternative is to use sqlite directly, a flat file, or something else to persist when you get kicked out of memory when backgrounded. This is what I'm dealing with now (FMDB) and finding I wish I had a lot of features that we get out of the box with CoreData.
Pat Zearfoss
Related Q & A:
- How to send invitation to my facebook friends from iOS app?Best solution by Stack Overflow
- Is it possible to open and flip through a Keynote in my own IOS app?Best solution by stackoverflow.com
- Where would you find a download for iOS 4 for Ipod touch 1st generation?Best solution by Yahoo! Answers
- What qualification do I need to be a social worker?Best solution by Yahoo! Answers
- Do you think Facebook has monopoly power in social networking?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.