In my controller, I have a button that reloads the controller with the following code, to hide the back button:
WKInterfaceController.reloadRootPageControllers(withNames: ["Record"], contexts: [], orientation: .vertical, pageIndex: 0)
When this code is triggered the awake
function is called again. My awake
function is as follows:
override func awake(withContext context: Any?) {
super.awake(withContext: context)
let track = context as! Track
locationManager.trackMetaData = track
//create new session
sessionManager.createNewSession(track: locationManager.trackMetaData!)
finishButton.setHidden(true)
}
The function sessionManager.createNewSession
can only be called once, and the parameter required for this function requires the context
parameter. How can I make sure this code is only called once? I could set a boolean variable in the init()
function, and then check it hasn't already been executed int his one, but is that the right way to go about it?