如何持久化NSMutableArray [英] How to persist a NSMutableArray
问题描述
I'm absolutely new to iOS Dev. I started out with the really helpful tutorial on Apple dev website
因此,我按照说明制作了一个简单的待办事项列表应用程序.
So i made the simple To-Do List application, as per instructions.
应用程序:这是一个简单的待办事项列表.它具有一个带有单个文本字段的视图,该视图接受一个输入,然后将该输入追加到表列表视图中.表列表视图是我的待办事项列表",它是由NSMutableArray生成的.
The App: It's a simple to-do list. It has a view, with a single text-field, which takes in an input, which then appends that input to the table-list view. the table list view is my "TO-Do List" which is generated from a NSMutableArray.
问题:每当我退出并重新启动该应用程序时,我的列表就会消失.
The Problem: Whenever i quit and relaunch the application, my List disappears.
问题:我需要一种方法来保存存储列表的NSMutableArray *ToDoList
.
The Question: I need a way to persist the NSMutableArray *ToDoList
which stores my list.
那么可以保留列表吗?还是我必须使用某种数据存储? 在询问并阅读有关将列表存储在"NSUserDefaults"中的内容之前,我做了一些研究-但问题是NsUserDefaults仅返回 im-mutable对象
So is it possible to persist the list? or will i have to make use of some kind of datastore? I did a little research before asking and read something about storing the list in 'NSUserDefaults' - but the problem being, NsUserDefaults, only returns an im-mutable Object
结论:
-
我们可以保留NsMutable列表吗?如果是,怎么办?
Can we persist the NsMutable List? If yes how?
是否需要使用NSUserDefaults?为什么?
Is NSUserDefaults necessary to use? Why?
如果(2)是,那么如何使返回的NsUserDefaults不可变对象可变?
If (2) is yes, then how do i make the returned immutable object of NsUserDefaults mutable?
再次,我应该告诉您,我掌握的iOS开发人员唯一的经验教训来自于本教程.因此,如果您将其分解为最简单的形式,我会喜欢的.
Yet again i should tell you, that the only hands on iOS dev i have is from the tutorial. So i would love it if you break it down to the simplest form.
谢谢.
推荐答案
1)如果只想保存NSMutableArray
,则可以,可以使用NSUserDefaults
.
1) If you just want to save an NSMutableArray
, then yes, you can use NSUserDefaults
.
2)如果您不想处理Core Data并设置适当的数据结构,那么这似乎是唯一的选择.
2) If you don't want to deal with Core Data and set up a proper data structure, then it seems like that's the only option.
3)从NSArray *array
中获取NSMutableArray
时,只需使用[array mutableCopy]
.
3) When you get an NSMutableArray
from an NSArray *array
, just use [array mutableCopy]
.
这篇关于如何持久化NSMutableArray的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!