开发者

Rule of thumb for when to store objects in Db for iPhone

Is there a good rule of thumb for when you should switch from having your objects in memory to store them in a database like Core Data/Sqlite on the iPhone/iPad?

I've heard (I think it was in Big Nerd Ranch, book) that 10.000 of simple objects is no problem at all to save and store from Doc开发者_如何学Pythonument directory on iPhone 3GS. But I guess when you have more complex releationships between objects its easier to store them in Core Data for example.

Whats your experience, Database or not to Database?


See this previous answer to a similar question.

Short summary:

  1. When data set is relatively small and with low complexity, you can use collections (NSArray, NSDictionary, NSSet) written to disk as plist.
  2. When data sets are very large but with low complexity e.g. a library card file where all the cards are exactly the same and unrelated to one another, then raw SQL can be a good solution.
  3. When complexity is high i.e. many different kinds of objects all related to one another, use Core Data regardless of the data size.

However, once you successfully climb Core Data's learning curve, it becomes so easy to use that you default to it all the time. I now employ it automatically even for things I once used arrays for.

If you intend to make a practice of writing Apple API apps, it would be a good use of your time to spend a week or two learning Core Data. It's not just a persistence API, it is an API for creating and using the entire model layer of the Model-View-Controller design that the Apple API uses,

(BTW, I'm pretty Big-Nerd Ranch's advice about plist based persistence applied to MacOS. Your memory and cpu constraints are much tighter on iOS devices. Plus, iOS devices use flash drives so the penalty for disk operation is far, far lower than for devices like desktops that use mechanical hard drives.)


Start out with the easiest storage method, plists or plain files probably. When (if) you actually notice problems with performance or data integrity, switch to a more powerful solution.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜