ios - how to initialize methods in a UIViewController inside of a viewDidLoad method -


there method creating data. method needs called once. structure:

var datacreated : bool? = false    override func viewdidload() {     super.viewdidload()      if datacreated! == false {         createdata()         self.datacreated = true     } } 

is right way ensure createdata() method called once? thank you.

since want createdata called once per instance of view controller, using viewdidload place call it. further, since viewdidload called once per instance of view controller, there no need datacreated property. can remove that.

override func viewdidload() {     super.viewdidload()      createdata() } 

another option call createdata init method of view controller. depends on createdata needs access. if createdata method needs access views , outlets, must use viewdidload.


Comments

Popular posts from this blog

minify - Minimizing css files -

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -