swift - iOS function similar ti viewDidLoad() -
i search function (included in ios or external library) similar viewdidload(). difference should searched function used when app starts first time, means when user opened app. viewdidload() used every time when view loaded. searched function xy() used when view loaded first time in runtime.
this normal version
user opened app, view 1 opens -> viewdidload() of view 1 -> user opens view 2 .... -> user goes view 1 -> viewdidload() of view 1
i search this
user opened app, view 1 opens -> viewdidload() of view 1 , function xy() -> user opens view 2 .... -> user goes view 1 -> viewdidload() of view 1 (this time not function xy() because view loaded in runtime)
thanks help!
you can place code need run once in dispatch_once
block obj-c , use static var
swift
obj-c:
- (void)viewdidload { [super viewdidload]; static dispatch_once_t oncetoken; dispatch_once(&oncetoken, ^{ // code place here run once }); }
swift 3
static var didinit = false override func viewdidload() { super.viewdidload() if myclass.didinit == false { myclass.didinit = true // code place here run once } }
Comments
Post a Comment