dispatch_once accessing ivar in swift3

This was my code in 2.2 and I want this this to happen only once of an appliation cycle. But in swift 3 we do similar kind of stuff using gloabal static variable.


But the problem is that I can't access ivar from that closure, can anybody has some idea how to achieve this?


  static private var token: dispatch_once_t = 0
  override func viewDidAppear(animated: Bool) {
    super.viewDidAppear(animated)

    dispatch_once(&DashboardViewController.token) {
      self.myIvar = something;
    }
  }

Replies

BTW swift 3 implementaion says something like this


  private static var once: () = {
   //self.myIvar = something
  //I can't access this
  }

Make the var lazy to initialize it after the instance is created.