Arrays 在swift 3中本地存储类对象
我在swift中存储“便笺”时遇到问题 这是笔记课Arrays 在swift 3中本地存储类对象,arrays,swift,object,local-storage,Arrays,Swift,Object,Local Storage,我在swift中存储“便笺”时遇到问题 这是笔记课 class Note { var title = "" var content = "" var color = UIColor() } 我收到这样的纸条 var notes: [Note] = [] 我加了几张便条 let note1 = Note() note1.title = "Houses" note1.content = "A knowledgable and experienc
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)
现在我需要保存并检索这些笔记,这样用户就可以在那里制作自己的笔记,并将它们保存在本地设备上
感谢您的帮助:)选择一个数据库或与之相当的数据库,学习如何保存数据 核心数据。显然 王国。我喜欢。您已经完成了一半的工作:
import RealmSwift
class Note: Object {
dynamic var title = ""
dynamic var content = ""
dynamic var color = "" // rgb value of "FF03A4", for instance
}
火基。新的和令人兴奋的
这完全取决于你的需要。第一步:找出你的需求是什么,然后参考每一个,找出它的优点。底线是,通过以一种可以检索(和保存)的方式定义数据,您已经完成了繁重的工作。你需要掌握数据持久性,才能对你的应用程序做最有用的事情(为你的用户记忆和定制)。C如果你是初学者,我现在就把它存储在.plist文件中(它最终将成为XML)。看:哦,不,我不是一个初学者,我已经编码了3-4年了,只是从来没有接触过存储数组,我只在用户数据中存储整数之类的东西