我遇到了在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)
现在我需要保存它们并检索这些笔记,以便用户可以自己制作笔记,并且可以在本地保存设备
感谢您的帮助:)
答案 0 :(得分:0)
选择db或db等效项,并了解如何保留数据。
核心数据。显然
境界。我的偏好。你已经完成了一半的工作:
import RealmSwift
class Note: Object {
dynamic var title = ""
dynamic var content = ""
dynamic var color = "" // rgb value of "FF03A4", for instance
}
火力地堡。新的和令人兴奋的
这完全取决于您的需求。第一步:弄清楚你的需求是什么,然后参考每个发现它的优势。最重要的是,您可以通过以可检索(并保存)的方式定义数据来完成繁重的任务。您需要掌握数据持久性,以便为您的应用做最有用的事情(为用户记住和自定义)。