arrays - Global Variable Not Working in Swift -


i have created small tabbed view program uses tabs switch between 2 views. there 1 global variable called list array containing information both views need access , change. however, when try use nsuserdefaults save array future use in app after closed, got error saying: "cannot convert value of type 'array<_>' expected argument type 'anyobject?'". here code second view:

@iboutlet weak var reminder: uitextfield! @iboutlet weak var label: uilabel! override func viewdidload() {  } @ibaction func submit(sender: anyobject) {     if reminder.text == "" {         label.text = "please type reminder!"     } else {         list.append(reminder.text!)         reminder.text = ""         label.text = "add reminder"     }      // below line giving error!!!!!      // fact using variable "list"      nsuserdefaults.standarduserdefaults().setobject(list, forkey: "reminders") }  override func didreceivememorywarning() {     super.didreceivememorywarning()     // dispose of resources can recreated. }  override func touchesbegan(touches: set<uitouch>, withevent event: uievent?) {     self.view.endediting(true) }  func textfieldshouldreturn(textfield: uitextfield) -> bool {     textfield.resignfirstresponder()      return true } 

i'm guessing has fact list variable global variable, appreciate diagnosing problem!

edit:

i have solved problem declaring global variable list this:

var list:[string] = string

instead of:

var list:array = []


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

python - pip wont install .WHL files -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -