ios - Receive user defaults which we stored when user logged in (swift3...) -
1) after logging retrieve values database( ok )
override func viewdidload() { super.viewdidload() // additional setup after loading view. // receive user defaults stored when user logged in let defaults = userdefaults.standard let firstname = defaults.string(forkey: "usernamevalue") let lastname = defaults.string(forkey: "namevalue") let connect_email = defaults.string(forkey: "emailvalue") let event_mois = defaults.array(forkey: "event_mois") }
2) after viewdidload()
make array feed display (ok)
var sections = [ section(genre: "🦁 event du mois", movies: ["the incredibles", "the incredibles"], expanded: false), section(genre: "💥 top event", movies: ["guardians of galaxy", "the flash", "the avengers", "the dark knight"], expanded: false), section(genre: "👻 event fribourg", movies: ["the walking dead", "insidious", "conjuring"], expanded: false) ]
3)i take event_mois table retrieved database put in var sections. can not use array outside of viewdidload
, can not put var sections in viewdidload.
can me? thank you
you need define sections
instance property of class, can access anywhere class.
class myviewcontroller: uiviewcontroller { var sections: [section]? override func viewdidload() { super.viewdidload() // receive user defaults stored when user logged in let defaults = userdefaults.standard let firstname = defaults.string(forkey: "usernamevalue") let lastname = defaults.string(forkey: "namevalue") let connectemail = defaults.string(forkey: "emailvalue") guard let eventmois = defaults.array(forkey: "event_mois") as? [section] else {return} if let sections = sections { sections.append(eventmois) } else { sections = eventmois } } }
and use swift naming convention, lower-camelcase variable names.
Comments
Post a Comment