【发布时间】:2017-11-09 05:37:57
【问题描述】:
我在 swift 中存储“笔记”时遇到了问题。
这里是笔记类
class Note {
var title = ""
var content = ""
var color = UIColor()
}
我得到这样的笔记
var notes: [Note] = []
我添加了一些注释
let note1 = Note()
note1.title = "Houses"
note1.content = "A knowledgable and experienced staff ready to help you build the… "
note1.color = #colorLiteral(red: 0.515632689, green: 0.2357951403, blue: 0.9598689675, alpha: 1)
let note2 = Note()
note2.title = "Note"
note2.content = "A beautifully redesined note app"
note2.color = #colorLiteral(red: 0.8978558183, green: 0.7694990635, blue: 0.2824732065, alpha: 1)
let note3 = Note()
note3.title = "Note"
note3.content = "A beautifully redesined note app"
note3.color = #colorLiteral(red: 0.2296327353, green: 0.8767140508, blue: 0.5295107365, alpha: 1)
let note4 = Note()
note4.title = "Note"
note4.content = "A beautifully redesined note app"
note4.color = #colorLiteral(red: 0.8787152171, green: 0.4267094135, blue: 0.2448620498, alpha: 1)
notes.append(note1)
notes.append(note2)
notes.append(note3)
notes.append(note4)
现在我需要保存它们并检索这些笔记,以便用户可以在那里制作自己的笔记,他们将保存在本地设备上
感谢您的帮助:)
【问题讨论】:
-
C o r e D a t a
-
如果你是初学者,我现在只存储在一个 .plist 文件中(它最终会是 XML)。见:stackoverflow.com/questions/27197658/…
-
哦,不,我不是初学者,我已经编码 3-4 年了,只是从来没有接触过存储数组,我只在 userdata 中存储了整数和类似的东西
标签: arrays swift object local-storage