Search code examples
swiftwatchkittitleidentifier

Set title for watch kit view


How do I set the title for the current view in my watch kit (swift) app programmatically?

By identifier I mean the three "hashtags"
enter image description here


Solution

  • You can set the title on the current Interface Controller, not a View. You just need to call setTitle() on the Interface Controller itself.

    One feasible method, where you can set the title for your controller is the awake(withContext:) function.

    class WatchController: WKInterfaceController {
        override func awake(withContext context: Any?) {
            self.setTitle("Title")
        }
    }