简体   繁体   English

iPhone应用程序开发中的数据库

[英]Database in iPhone app development

I'm creating an app for iPhone, and I want it to load data from an external file (from an URL in a server), to display the hints. 我正在为iPhone创建一个应用程序,并且希望它从外部文件(从服务器中的URL)加载数据以显示提示。

I have read several tutorials, but I don't know yet what is more convenient for me: 我已经阅读了一些教程,但是我还不知道什么对我来说更方便:

  • Do I use CoreData? 我是否使用CoreData?
  • Do I create a .sql file and I try to do queries inside the code of my app? 我是否创建一个.sql文件,并尝试在我的应用程序代码内进行查询?
  • Do I use a .txt file and try to parse it? 我是否使用.txt文件并尝试对其进行解析?
  • Do I use a .xml file? 我是否使用.xml文件?

I have to say I'm quite lost at this point, and I really don't know what would be more effective, easy to write (code). 我不得不说,我现在已经迷失了,我真的不知道什么会更有效,更容易编写(代码)。 And I don't how to access to a file that is in a server and not in the folder of the app itself. 而且,我不访问服务器中而不是应用程序本身文件夹中的文件。

If your loading data from an external server take a look at Rest Kit. 如果您是从外部服务器加载数据,请查看Rest Kit。 It allows you to map an API to objects that are backed by Core Data. 它允许您将API映射到由Core Data支持的对象。 http://restkit.org/ http://restkit.org/

Personally I would use CoreData simply because you get a lot of power out of the box right from Core Data, instead of trying to deal with raw sql queries or parsing data. 就我个人而言,我之所以使用CoreData只是因为您可以直接从Core Data获得很多功能,而不是尝试处理原始sql查询或解析数据。

Another option if your looking for the simplest way to grab a file from a server and map it to an object is to look at .plists for example: 如果您正在寻找从服务器获取文件并将其映射到对象的最简单方法,则另一种选择是查看.plists,例如:

NSDictionary *data = [dict initWithContentsOfURL:[NSURL URLWithString:@"http://server.com/data.plist"]];

Although be careful with that call though because its not asynchronous, and if the file is large and call is made from the Main thread it will block the application. 尽管由于该调用不是异步的,所以请谨慎使用它,并且如果文件很大并且调用是从Main线程进行的,它将阻止应用程序。

The best way to implement database on iPhone SDK is to use CORE Data. 在iPhone SDK上实现数据库的最佳方法是使用CORE数据。
- It prevents you to write long sql scripts to fetch & write data in db. -它防止您编写长的SQL脚本来获取和写入db中的数据。
- Easy Implementation. -易于实施。
- Excellent UI to simulate. -出色的用户界面来模拟。
- portable -便携式
- Can upgrade later if any enhancement required after some time. -如果一段时间后需要任何增强功能,可以稍后升级。

So I would like to suggest you to save your data using Core Data. 因此,我建议您使用“核心数据”保存数据。 you need to fetch your data from server & call simple methods to save it into App DB using Core data. 您需要从服务器获取数据并调用简单方法以使用Core数据将其保存到App DB中。 You even dont need to do much manipulation into it. 您甚至不需要对其进行太多操作。

Following are some Nice Links for some tutorials: 以下是一些教程的一些尼斯链接:
http://mobile.tutsplus.com/tutorials/iphone/advanced-restkit-development_iphone-sdk/ http://mobile.tutsplus.com/tutorials/iphone/iphone-core-data/ http://mobile.tutsplus.com/tutorials/iphone/advanced-restkit-development_iphone-sdk/ http://mobile.tutsplus.com/tutorials/iphone/iphone-core-data/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM