ios - Permanently saving data using swift 3 -
i made todo list app enter task in 1 view controller , saves data in array of view controller , adds table. problem when close app, new task data gone. can help?
i tried using userdefaults didn't work quite or didn't use right.
this code view controller type in new task:
@ibaction func addtaskbutton(_ sender: any) { if (textfield.text != "") { task.append(textfield.text!) let task = userdefaults.standard.set(task, forkey: "xx") textfield.text = "" textlabel.text = "saved!" timer = timer.scheduledtimer(timeinterval: 1.6, target: self, selector: #selector(addtaskviewcontroller.hide), userinfo: nil, repeats: true) textlabel.ishidden = false } }
this code view controller try save data , place in table
var task = ["pray", "code", "work-out"] var school = ["email collin college","email pqc","create file doccumensts"] var shoppinglist = ["kd9 black","roshrun black","nike huarache black","white shirt","black shirt", "black work out pnats", "white socks"] var prayer = ["school","family","drive & grace"] var workout = ["legs","caffs","push ups","arms","chest press","squats", "back"] class add_task_tableviewcontroller: uiviewcontroller,uitableviewdelegate, uitableviewdatasource { @iboutlet weak var tasktableview: uitableview! public func tableview(_ tableview: uitableview, numberofrowsinsection section: int) -> int { return (task.count) } public func tableview(_ tableview: uitableview, cellforrowat indexpath: indexpath) -> uitableviewcell { let cell = uitableviewcell(style: uitableviewcellstyle.default, reuseidentifier: "cell") cell.textlabel?.text = task[indexpath.row] return(cell) } func tableview(_ tableview: uitableview, commit editingstyle: uitableviewcelleditingstyle, forrowat indexpath: indexpath) { if editingstyle == uitableviewcelleditingstyle.delete { task.remove(at: indexpath.row) tasktableview.reloaddata() } } override func viewdidappear(_ animated: bool) { tasktableview.reloaddata() }
you can use sqlite database maintain draft messages or values can used later when open app again.
wiki
Comments
Post a Comment