ios - Use userdefaults on a struct -


i manually entering data struct. struct not saving data. tried use userdefaults it's not working. want data appear on label bencarson @ times if it's in struct bad.

viewcontroller 1

struct bad {     static var mm = [string]() } 

viewcontroller 2

class viewcontroller2: uiviewcontroller {     @iboutlet var bencarson: uilabel!     override func viewdidload() {         super.viewdidload()         bencarson.text = viewcontroller.bad.mm.map { " \($0)" }.joined(separator:"\n")     } } 

i think no need struct use userdefaults , work

for save

let mm = ["adsa", "safds", "twer", "qwer", "dfas"] let defaults = userdefaults.standard defaults.set(mm, forkey: "savedstringarray") defaults.synchronize() 

for retrieve

let defaults = userdefaults.standard let myarray = defaults.stringarray(forkey: "savedstringarray") ?? [string]() bencarson.text = myarray.map { " \($0)" }.joined(separator:"\n") 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -