在 Xcode 中编辑 plist
我想从 Xcode 编辑一个 plist,我将用它来填充表格视图。
问题是我有一组图像,用户可以将其中一个图像添加到收藏夹列表中。
这需要写入plist。所以我需要图像的索引号以及他们选择保存图像的名称。我怎样才能写入plist?
然后,当他们查看收藏夹并选择表中的项目时,需要加载并显示适当的图像。
我正在考虑编写他们选择的名称以及附加的索引号,例如“index_titleSaved”,然后从 plist 中读取时我可以抓取第一个 _ 之前的数字。然后展示它。
这是一个好方法还是可以更有效地完成?
提前致谢。
I would like to edit a plist from Xcode which I will use to fill the table view.
The thing is I have an array of images, and the user can add one of these images to a favorites list.
This needs to be written to the plist. So I need the index number of the image and the name they choose to save it with. How can I write to a plist?
Then when they view favorites and they select an item in the table, that needs to load and display the appropriate image.
I was thinking of writing the name they choose with the number of the index appended with for e.g. "index_titleSaved" and then when reading from the plist I could just grab the number before the first _. and then show it.
Is this a good way or could it be done more efficiently?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 NSDictionary 的 writeToFile 方法,或者,如果您想要一个数组(或字典数组),请使用 NSArray 的 writeToFile 方法。
You can use an NSDictionary's
writeToFile
method, or, if you want an array (or an array of dictionarys), use NSArray'swriteToFile
method.根据你的第二个问题,我认为你的应用程序崩溃是因为 Array 使用数字键并且不能使用 NSString 作为键。如果您需要键->值结构,则必须使用 NSDictionary
According to your second question, I think your app crash because Array use a numeric key and can't use NSString as key. If you need a key->value structure you have to use NSDictionary
我认为你想要使用的是
I think what you are trying to use is