ios - Store array of tasks in CoreData or UserDefaults in Swift -


i creating app add task pressing button, cell has custom cell populates tableview information user type in textviews, problem having hard time save array using userdefaults(the method know), app crashes when press addbutton, guys point me right direction please ? thanks.

i have customcell here:

 import uikit   class celulacustomizada: uitableviewcell //custom cell {      @iboutlet weak var imagemdefesa: uiimageview!      @iboutlet weak var nomelabeldefesa: uilabel!      @iboutlet weak var levellabeldefesa: uilabel!      }  import uikit  var taskmgr: taskmanager = taskmanager()  struct task {     var name = "un-named"     var desc = "un-described"     var image : uiimage } 

i call function append array when press button getting error in userdefaults.

class taskmanager: nsobject     {         var tasks = [task]()          func addtask(name: string, desc: string, image: uiimage)         {             tasks.append(task(name: name, desc: desc, image: image))         }     } 

i want call function save data when press button

class viewcontroller: uiviewcontroller, uitableviewdelegate, uitableviewdatasource, uitextfielddelegate {     @iboutlet weak var txttask: uitextfield!     @iboutlet weak var txtdesc: uitextfield!      @iboutlet weak var tableviewtasks: uitableview!      override func viewdidappear(_ animated: bool)     {      }      override func viewdidload()     {         super.viewdidload()      }      @ibaction func addbutton(_ sender: any)     {         taskmgr.addtask(name: txttask.text!, desc: txtdesc.text!, image: #imageliteral(resourcename: "cannon"))         self.view.endediting(true)          txttask.text = ""         txtdesc.text = ""            /*its giving me error , crashing app saying "" 'nsinvalidargumentexception', reason: 'attempt insert non-property list object (     "mytaskclash.task(name: \"\", desc: \"\", image: <uiimage: 0x60800009d3d0>, {199, 170})"     ) key tasks' */         userdefaults.standard.set(taskmgr.tasks, forkey: "tasks")           tableviewtasks.reloaddata()      } 


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -