从文本文件导入 arrayWithObjects 的 NSString 对象
我是开发新手,我正在尝试创建一个简单的词典应用程序供个人在 iPhone 上使用。对于上下文,我的问题是 这个问题的后续问题 你们中的一些人昨天很友善地回答了。
是否可以创建一个方法:
- 读取文本文件
- 将文件中的文本字符串转换为 NSStrings
- 使用 NSStrings 填充 NSArray 以创建 arrayWithObjects
任何帮助或示例代码将不胜感激!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将文本文件格式化为有用的数据结构并解析它将是最难的部分。但是,只要您的 NSArray 或 NSDictionary 只包含 plist 可序列化对象,例如 NSString 就可以考虑使用简单的序列化。
您可以使用它来保存:(其中 array 是要保存的数组,path 是文件路径的 NSString)
并且可以从文件中加载:
您还可以使用
NSJSONSerialization
来创建和结构化字符串并通过更通用的方式保存它。Formatting the text file to be a useful data structure and parsing it would be the hardest part. But, as long as your
NSArray
orNSDictionary
contain onlyplist
serializable objects, likeNSString
s consider just using simple serialization.You could use this to save: (Where array is the array to save and path is an NSString of the file path)
And this to load from the file:
You could also use
NSJSONSerialization
to create and structured string and save it through more general means.