简体   繁体   English

在iPod Touch / iPhone Objective-C中保存数据的最佳方法

[英]Best way to save data in iPod Touch/iPhone Objective-C

I am writing a very simple application, for the iPhone. 我正在为iPhone编写一个非常简单的应用程序。 Unfortunately I am really a newbie. 不幸的是我真的是一个新手。 What I am trying to do is to save data at the end of a user experience. 我想做的是在用户体验结束时保存数据。 This data is really simple, only string or int, or some array. 这个数据真的很简单,只有字符串或整数,或者是一些数组。

Later I want to be able to retrieve that data, therefore I also need an event ID (I suppose). 稍后,我希望能够检索该数据,因此,我还需要一个事件ID(我想)。

Could you please point out the best way, API or technology to achieve that, XML, plain text, serialization... ? 您能否指出实现此目标的最佳方法,API或技术,XML,纯文本,序列化...?

Use NSUserDefaults . 使用NSUserDefaults Straight forward and easy to use. 直截了当,易于使用。 This will handle all File I/O for you, and takes only a couple lines of code. 这将为您处理所有文件I / O,并且只需要几行代码。

NSUserDefaults is a good choice for small amounts of data. NSUserDefaults是处理少量数据的不错选择。

If you need to manage something larger than a kilobyte or so, you might consider using the initWithContentsOfFile: methods of NSArray or NSDictionary to read in a .plist file. 如果您需要管理大于一千字节左右的内容,则可以考虑使用NSArrayNSDictionaryinitWithContentsOfFile:方法来读取.plist文件。 To write the file, use the writeToFile:atomically: methods. 要写入文件,请使用writeToFile:atomically:方法。 This file needs to go in your app's documents directory. 该文件需要进入您应用程序的文档目录中。

Me and my team created a simple class for this purpose which as Mark pointed out makes use of NSUserDefaults . 我和我的团队为此目的创建了一个简单的类,正如Mark指出的那样,它使用NSUserDefaults Hopefully this helps you out... 希望这可以帮助您...

http://getsetgames.com/2009/10/07/saving-and-loading-user-data-and-preferences/ http://getsetgames.com/2009/10/07/saving-and-loading-user-data-and-preferences/

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

相关问题 保存自定义Objective-c对象的层次结构以实现持久性的最佳方法 - Best way to save a hierarchy of custom Objective-c objects for persistence 硬编码这些数据的最佳方法是什么? Objective-C的 - What is the best way of hardcoding this data. Objective-C 在Objective-C中存储和加载大量数据的最佳方法 - Best way to store and load large amount of data in Objective-C 在Objective-C中定义常量的最佳方法 - Best way to define Constants in Objective-C 有没有一种方法可以将Node.JS与Objective-C / iPhone SDK集成在一起? - Is there a way to integrate Node.JS with Objective-C/iPhone SDK? 客观的C方法来检测使用的设备是否是iPod - objective C way to detect if the used device is an iPod 在Objective-C中实现此滚动UI的最佳方法是什么? - What is the best way to implement this scrolling UI in Objective-C? 在Objective-C iOS应用中创建用户身份验证的最佳方法 - Best way to create an user authentication in Objective-C iOS App 在Objective-C中以特定间隔增加NSDateComponents的最佳方法是什么? - What is the best way to increment NSDateComponents in specific intervals in Objective-C? 简化/重构表的最佳方法查看Objective-C中的代码设置 - Best way to simplify/refactor tableView code setup in objective-c
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM