Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
454 views
in Technique[技术] by (71.8m points)

iphone - Should I save in plist or Core Data?

I'm wondering if I should save data in my app to a plist or using Core Data..

My app is just basically saving tweets from timeline and other users now. Which is less than a few hunderd kB (about 200 kb in my testing). What's the advantages of using core data?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

just some advices that could help in your app design.

First of all would be nice to underline that CoreData is not really comparable with plist. What I mean is that CoreData is like a data model abstraction layer over your data storage that allow you to manage relationships and fetching rules between different data entities. Behind the CoreData layer, your data storage could be based on plist (osx only), sqlite database or binary object.

This is also important because help you to understand the scope of CoreData: if you need to keep logical relationship between different data entities or perform multiple queries over the same data or serialize/deserialize big data structures, CoreData provides the best and fastest solution to make it happen. If you just need to store a plain list of items that just need to be displayed, a bounce of plist file should be enough.

Another important decision point is the type of data you need to store: according to Apple, plist files are optimized for strings, numbers, dates and some binary data. This is what Apple says about plist:

Note that property lists should be used for data that consists primarily 
of strings and numbers. They are very inefficient when used with large blocks 
of binary data.
Many applications require a mechanism for storing information that will 
be needed at a later time. For situations where you need to store small 
amounts of persistent data — say less than a few hundred kilobytes — property 
lists offer a uniform and convenient means of organizing, storing, and 
accessing the data.

It means that if you need to store "heavy" stuff or complex objects and manage them (like search trough them), the caching system of the plist parser could be inefficient (mostly on iOS).

In my opinion, your idea to store around 200k of linear tweets (around 1000 tweets?) from a timeline will works fine with a plist based solution. Also consider that the plist parser is strongly accelerated with small data structure then you will have better performance and low memory usage (mostly during startup) because you don't need to initialize CoreData nor any other "code wrapper" around your data storage. Just a simple on-the-fly usage of NSDictionary, NSArray and so on.

Last but not least, the plist implementation is cheap enough to give you the possibility to move on CoreData in a next step.

What I mean is that sometimes it's not necessary to use a tank if you need to catch some flies :-)

Hope this helps. Ciao!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...