保存数据 - 核心数据与plist文件

时间:2021-10-18 16:31:44

I'm writing an iOS applications that saves Music albums(just an exercise I'm doing for the fun of it) . For every Album there's a singer, song names, time, and a picture The final result will be a lot of objects with a lot of details including a picture attached to every object. Should I even consider doing something like that with plist? (can pictures be stored in a plist?)

我正在编写一个可以保存音乐专辑的iOS应用程序(这只是我为了它的乐趣所做的练习)。对于每个专辑,都有歌手,歌曲名称,时间和图片最终结果将是很多具有许多细节的对象,包括附在每个对象上的图片。我是否应该考虑用plist做类似的事情? (图片可以存储在plist中吗?)

What's the best way to save and access that data? I'm new to iOS and from the training videos I've seen Core Data is not recommend for the beginner user. Is that really the case?

保存和访问数据的最佳方法是什么?我是iOS的新手,从培训视频中我看到Core Data不推荐给初学者用户。那是真的吗?

If I'm going with plist, should I create one plist for every genre for example rap.plist , rock.plist etc' or just a big data.plist?

如果我要使用plist,我应该为每种类型创建一个plist,例如rap.plist,rock.plist等'或者只是一个大数据.plist?

Thanks

谢谢

6 个解决方案

#1


0  

I think the best way you can do this, since you are new to IOS is by using sqlite. Save all the information you want in your local database and display it on the screen.

我认为你可以做到这一点的最佳方式,因为你是IOS的新手是使用sqlite。将所需的所有信息保存在本地数据库中并将其显示在屏幕上。

You can use plist if you have data structure that is small.

如果数据结构很小,可以使用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. A property list is probably the easiest to maintain, but it will be loaded into memory all at once. This could eat up a lot of the device's memory.

With Sqlite you will easily be able delete , edit, insert your data into the database. 

Core data also uses sqlite for data storage only it helps you to manage your data objects, their relationships and dependencies with minimal code.

And since your are new getting started with core data would not be such a good idea i think.. so i would suggest start off with normal sqlite. Save the data in one of your folders of your app and store their path in the database.

而且,因为你是新的核心数据开始不会是一个好主意我想..所以我建议从正常的sqlite开始。将数据保存在应用程序的某个文件夹中,并将其路径存储在数据库中。

You dont have to write different plists.. You can use the same one if you are using.

您不必编写不同的plist ..如果您使用,可以使用相同的plist。

EDIT : here is a link that will help you with learning sqlite

编辑:这是一个链接,将帮助您学习sqlite

http://www.iosdevelopment.be/sqlite-tutorial/

http://www.iosdevelopment.be/sqlite-tutorial/

#2


2  

I would go for core data. If you choose the right template when you create your new project in xcode then reduce the once-off overhead work significantly.

我会去寻找核心数据。如果在xcode中创建新项目时选择了正确的模板,则可以显着减少一次性开销工作。

With that simple structure I would say that the templates provides nearly everything you need. Just define your model and layout and off you go.

有了这个简单的结构,我会说模板提供了你需要的几乎所有东西。只需定义您的模型和布局,然后就可以了。

There is just the images where I would spend a bit more time in thinking it over. I personally never put the image data into core data itself. I rather stored them as file and within my core data model I just stored the path and filename to access it. As file name I simply used a timestamp. You could use some auto-increment or other unique id technique but a time stamp would do as well. It will not be visible to the user anyway.

只有图像,我会花更多的时间来思考它。我个人从未将图像数据本身放入核心数据中。我宁愿将它们存储为文件,在我的核心数据模型中,我只存储了路径和文件名来访问它。作为文件名,我只使用了时间戳。您可以使用一些自动增量或其他唯一ID技术,但时间戳也可以。无论如何,它都不会被用户看到。

#3


1  

you need some more code to set up the core data stack (the store coordinator, the store, the object model, and a context)

您需要更多代码来设置核心数据堆栈(商店协调员,商店,对象模型和上下文)

it is a tad more complicated but that shouldnt scare you off. Reading a plist is indeed dead easy but while good for smaller data (like the info.plist) it doesnt scale and soon you need a fullblown DB

它有点复杂,但不应该吓跑你。读一个plist确实很容易,虽然对于较小的数据(如info.plist)有好处,但它不能扩展,很快就需要一个完整的数据库

#4


0  

As you edited your original question an decided to go with plist now. In that case I would go for one plist per ablum and one overall plist for the list of albums. You could, of course, use more plists for categories etc.

当您编辑原始问题时,现在决定使用plist。在这种情况下,我会选择每个ablum的一个plist和一个专辑列表的整体plist。当然,你可以使用更多的plists作为类别等。

However, if you are thinking of data structures like categories you are far better off with core data. Especially when it comes to searching.

但是,如果您正在考虑类别等数据结构,那么使用核心数据会更好。特别是在搜索方面。

#5


0  

No one seems to be mentioning SQLLite, I would go that way and for reasons that I explain here ( https://*.com/a/12619813/1104563 ). Hope this helps!

似乎没有人提到SQLLite,我会这样做,并且由于我在这里解释的原因(https://*.com/a/12619813/1104563)。希望这可以帮助!

#6


-2  

coredata is a apple provided persistant tool, while plist is XML file. The reason why core data is not recommended for beginner, I think, is core data is more difficult than plist from programming perspective. For your application, obviously core data is more suitable. But alternatively, you may also use archive file, that's between core data and plist.

coredata是一个苹果提供的持久工具,而plist是XML文件。我认为,不建议初学者使用核心数据的原因是核心数据比编程视角下的plist更难。对于您的应用,显然核心数据更合适。但另外,您也可以使用归档文件,即核心数据和plist之间的归档文件。

#1


0  

I think the best way you can do this, since you are new to IOS is by using sqlite. Save all the information you want in your local database and display it on the screen.

我认为你可以做到这一点的最佳方式,因为你是IOS的新手是使用sqlite。将所需的所有信息保存在本地数据库中并将其显示在屏幕上。

You can use plist if you have data structure that is small.

如果数据结构很小,可以使用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. A property list is probably the easiest to maintain, but it will be loaded into memory all at once. This could eat up a lot of the device's memory.

With Sqlite you will easily be able delete , edit, insert your data into the database. 

Core data also uses sqlite for data storage only it helps you to manage your data objects, their relationships and dependencies with minimal code.

And since your are new getting started with core data would not be such a good idea i think.. so i would suggest start off with normal sqlite. Save the data in one of your folders of your app and store their path in the database.

而且,因为你是新的核心数据开始不会是一个好主意我想..所以我建议从正常的sqlite开始。将数据保存在应用程序的某个文件夹中,并将其路径存储在数据库中。

You dont have to write different plists.. You can use the same one if you are using.

您不必编写不同的plist ..如果您使用,可以使用相同的plist。

EDIT : here is a link that will help you with learning sqlite

编辑:这是一个链接,将帮助您学习sqlite

http://www.iosdevelopment.be/sqlite-tutorial/

http://www.iosdevelopment.be/sqlite-tutorial/

#2


2  

I would go for core data. If you choose the right template when you create your new project in xcode then reduce the once-off overhead work significantly.

我会去寻找核心数据。如果在xcode中创建新项目时选择了正确的模板,则可以显着减少一次性开销工作。

With that simple structure I would say that the templates provides nearly everything you need. Just define your model and layout and off you go.

有了这个简单的结构,我会说模板提供了你需要的几乎所有东西。只需定义您的模型和布局,然后就可以了。

There is just the images where I would spend a bit more time in thinking it over. I personally never put the image data into core data itself. I rather stored them as file and within my core data model I just stored the path and filename to access it. As file name I simply used a timestamp. You could use some auto-increment or other unique id technique but a time stamp would do as well. It will not be visible to the user anyway.

只有图像,我会花更多的时间来思考它。我个人从未将图像数据本身放入核心数据中。我宁愿将它们存储为文件,在我的核心数据模型中,我只存储了路径和文件名来访问它。作为文件名,我只使用了时间戳。您可以使用一些自动增量或其他唯一ID技术,但时间戳也可以。无论如何,它都不会被用户看到。

#3


1  

you need some more code to set up the core data stack (the store coordinator, the store, the object model, and a context)

您需要更多代码来设置核心数据堆栈(商店协调员,商店,对象模型和上下文)

it is a tad more complicated but that shouldnt scare you off. Reading a plist is indeed dead easy but while good for smaller data (like the info.plist) it doesnt scale and soon you need a fullblown DB

它有点复杂,但不应该吓跑你。读一个plist确实很容易,虽然对于较小的数据(如info.plist)有好处,但它不能扩展,很快就需要一个完整的数据库

#4


0  

As you edited your original question an decided to go with plist now. In that case I would go for one plist per ablum and one overall plist for the list of albums. You could, of course, use more plists for categories etc.

当您编辑原始问题时,现在决定使用plist。在这种情况下,我会选择每个ablum的一个plist和一个专辑列表的整体plist。当然,你可以使用更多的plists作为类别等。

However, if you are thinking of data structures like categories you are far better off with core data. Especially when it comes to searching.

但是,如果您正在考虑类别等数据结构,那么使用核心数据会更好。特别是在搜索方面。

#5


0  

No one seems to be mentioning SQLLite, I would go that way and for reasons that I explain here ( https://*.com/a/12619813/1104563 ). Hope this helps!

似乎没有人提到SQLLite,我会这样做,并且由于我在这里解释的原因(https://*.com/a/12619813/1104563)。希望这可以帮助!

#6


-2  

coredata is a apple provided persistant tool, while plist is XML file. The reason why core data is not recommended for beginner, I think, is core data is more difficult than plist from programming perspective. For your application, obviously core data is more suitable. But alternatively, you may also use archive file, that's between core data and plist.

coredata是一个苹果提供的持久工具,而plist是XML文件。我认为,不建议初学者使用核心数据的原因是核心数据比编程视角下的plist更难。对于您的应用,显然核心数据更合适。但另外,您也可以使用归档文件,即核心数据和plist之间的归档文件。