There is a function which is need execute once in "view will appear".How should i do to solve the problem.
i have try
dispatch_once(&token) {     
}
But the 'dispatch once' is deprecated, so i am in trouble now.
There is a function which is need execute once in "view will appear".How should i do to solve the problem.
i have try
dispatch_once(&token) {     
}
But the 'dispatch once' is deprecated, so i am in trouble now.
 
    
    If you are doing this to spin up a single instance of some object for every instance of that view controller to share, then you may want to use lazy instantiation of a static property.
For example:
class Foo: UIViewController {
    static var monkey: Animal!
    func getMonkey() -> Animal {
        if Foo.monkey == nil {
            Foo.monkey = Monkey()  // we only make a new one if we don't have one
        }
        return Foo.monkey
    }
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        getMonkey().doSomething()  // you will always get the same monkey
    }
}
