ios 什么数据库更适合iOS应用程序开发以及如何实现搜索?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14428350/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What database is preferable for iOS app development and how to implement search?
提问by user1995213
For the past 2 weeks I have been reading and learning on how to create an iPhone App using these books: Beginning iOS 6 development, Storyboarding, and Using and Learning Objective C. I have been going through tutorials online and through these books but haven't been able to find what I am looking for.
对于在过去的2个星期,我一直在阅读和学习如何使用这些书籍来创建iPhone应用程序:开始的iOS 6开发,故事板,并使用和学习目标C。我一直在浏览在线教程和这些书籍,但一直找不到我要找的东西。
I am creating a simple app that is a list of animals which would be searchable, and then when you click on the individual animal it shows information about it (name, picture, weight, and native location). I would like to be able to search via the common name or its species, and the user be able to select the animal and read the information about it. There is no adding new animals or editing the list. Next I would like to be able to also sort by continent. So for example the first Scene would have Animal as one cell and Continents in the other. If they click Animals, it pulls up all the animals and has a UISearchbar to search through all the animals, which they can proceed to click on. If they click continent (Australia), it would populate a searchable list only in that location.
我正在创建一个简单的应用程序,它是一个可搜索的动物列表,然后当您单击单个动物时,它会显示有关它的信息(名称、图片、体重和本地位置)。我希望能够通过通用名称或其物种进行搜索,并且用户能够选择动物并阅读有关它的信息。没有添加新动物或编辑列表。接下来,我还希望能够按大陆进行排序。例如,第一个场景将 Animal 作为一个单元格,而 Continents 在另一个单元格中。如果他们点击 Animals,它会拉出所有的动物,并有一个 UISearchbar 来搜索所有的动物,他们可以继续点击。如果他们单击大陆(澳大利亚),它将仅在该位置填充可搜索列表。
My question is: How would I create a database that links these variables together, and then be able to search via the search bar (plist, core data, sqlite)? What resource should I use for a learning tool or tutorial?
我的问题是:如何创建一个将这些变量链接在一起的数据库,然后能够通过搜索栏(plist、核心数据、sqlite)进行搜索?我应该使用什么资源作为学习工具或教程?
采纳答案by rmaddy
The best choice depends on the amount and complexity of the data. If you only have a few hundred animals with a few attributes per animal then putting all of the data in a plist and loading all of the data into memory is fine.
最佳选择取决于数据的数量和复杂性。如果你只有几百只动物,每只动物有几个属性,那么将所有数据放在 plist 中并将所有数据加载到内存中就可以了。
If you have more data with large notes and other attributes, then you may not be able to load all of the data into memory. Then using SQLite would be a better option.
如果您有更多带有大笔记和其他属性的数据,那么您可能无法将所有数据加载到内存中。那么使用 SQLite 将是一个更好的选择。
Core data is another option but it has the biggest learning curve and may be overkill for such simple data. Core data would be a good choice is the data was not read-only, if you had more relationships, and you wanted to sync the user data across devices.
核心数据是另一种选择,但它具有最大的学习曲线,对于这样简单的数据来说可能有点矫枉过正。核心数据将是一个不错的选择,因为数据不是只读的,如果您有更多关系,并且您希望跨设备同步用户数据。
回答by darbid
It is good that you are reading all those things. I will try to create a "dumbed down" answer for you.
很高兴您正在阅读所有这些内容。我将尝试为您创建一个“愚蠢”的答案。
You ask about a database. This means for you where do I store the data. Apple and most technical people talk about this with the words Persistence or where do I persist the data.
你问一个数据库。这对你来说意味着我在哪里存储数据。Apple 和大多数技术人员用持久性或我在哪里保存数据来谈论这个。
The three commonly used (but I am sure not exclusive) methods of storage is:
三种常用的(但我确定不是唯一的)存储方法是:
(1) in a text file known as a plist file
(2) in a text file in xml format and
(3) in a sqlite file or database file
(1) 在称为 plist 文件
的文本文件中 (2) 在 xml 格式的文本文件中
(3) 在 sqlite 文件或数据库文件中
How do I access this data?
我如何访问这些数据?
You are then going to hear about CoreData, CoreData was introduced by Apple to make it easier to access your stored data and also to help the small devices deal with large amounts of data. Accesing a Sqlite database without coredata needs a bit of work, but because of CoreData they make this easier.
然后你会听到 CoreData,CoreData 是由 Apple 引入的,目的是让你更容易地访问你存储的数据,并帮助小型设备处理大量数据。在没有 coredata 的情况下访问 Sqlite 数据库需要一些工作,但由于 CoreData,它们使这变得更容易。
As for the xml and plist, these can be accessed by simply reading the file into an Array or Dictionary and then you either search for or show data from those objects as you normally do.
至于 xml 和 plist,可以通过简单地将文件读入数组或字典来访问它们,然后像往常一样搜索或显示来自这些对象的数据。
(one thing about the sqlite/core data idea is that when setting up CoreData you can set up a sqlite data base or it can be in xml format.)
(关于 sqlite/core 数据思想的一件事是,在设置 CoreData 时,您可以设置一个 sqlite 数据库,也可以是 xml 格式。)
Once you know these two things, then you can mix and match based on what is needed for your purpose. If you have a large amount of data and do a lot with it then a sqilte file with CoreData access is going to be a good choice. If it is a very small amount of information then you can use a simple plist file and use a Array or Dictionary object to get the information, use it and then store it again in the file.
一旦你知道了这两件事,你就可以根据你的目的需要混合和匹配。如果您有大量数据并用它做很多事情,那么具有 CoreData 访问权限的 sqlte 文件将是一个不错的选择。如果信息量非常小,那么您可以使用简单的 plist 文件并使用 Array 或 Dictionary 对象来获取信息,使用它然后再次将其存储在文件中。
In your case it does sound like a simple plist would work.
在你的情况下,它听起来像一个简单的 plist 可以工作。
回答by Rob
Core Data is often sited as the preferred iOS database technology and if you want to gain some familiar with databases in iOS, you should probably just start there. Use your favorite search engine and look for "Core Data Tutorial". Ray Wenderlichoften does a good job in his tutorials, and you should definitely check out the Apple links (the videos and various "getting started" documents found at http://developer.apple.com). Go through a tutorial or two before you consider posting follow-up questions on Stack Overflow.
Core Data 通常被选为首选的 iOS 数据库技术,如果您想熟悉 iOS 中的数据库,您可能应该从那里开始。使用您最喜欢的搜索引擎并查找“核心数据教程”。Ray Wenderlich在他的教程中经常做得很好,您绝对应该查看 Apple 链接(在http://developer.apple.com 上找到的视频和各种“入门”文档)。在考虑在 Stack Overflow 上发布后续问题之前,先阅读一两个教程。