An interface element that toggles between an On and Off state.


Switches are commonly used to indicate whether a feature is enabled or disabled. You set the initial value of the switch in your storyboard file, but you can modify that value at runtime using the methods of this class.

Do not subclass or create instances of this class yourself. Instead, define outlets in your interface controller class and connect them to the corresponding objects in your storyboard file. For example, to refer to a switch object in your interface, define a property with the following syntax in your interface controller class:

@IBOutlet weak var mySwitch: WKInterfaceSwitch!

During the initialization of your interface controller, WatchKit creates a new instance of this class and assigns it to your outlet. At that point, you can use the object in your outlet to make changes to the onscreen switch.

When the user changes the value of a switch, WatchKit delivers the new value to the slider’s action method. The format of a switch’s action method is as follows:

@IBAction func switchAction(value: Bool)

Declare a method of this form in the interface controller class used to manage the switch. You can change the method name to anything you like. When configuring the switch in Xcode, connect its selector to your custom action method.

Additional Information About Switches in watchOS 1

In watchOS 1, WatchKit coalesces the data from all setter method calls made during the same run loop iteration and transmits that data to the user’s Apple Watch at the end of the run loop. If you set an attribute to different values in the same run loop iteration, only the last value is transmitted. If you set an attribute to the same value in the same run loop iteration, WatchKit generates a log message so that you can track down the duplicate change.

Interface Builder Configuration Options

Xcode lets you configure information about switches in your storyboard file. Table 1 lists the attributes you can configure and their meaning.

Table 1

WatchKit switch attributes




The initial state of the switch. The switch can be off or on. You can modify the state of the switch programmatically at runtime using the setOn(_:) method.


The color of the switch when it is in the on state.


A checkbox indicating whether the switch is enabled. An enabled switch calls its action method when the user changes the state of the switch. You can enable or disable a switch programmatically using the setEnabled(_:) method.


The string to be displayed next to the switch. If specified, the title string is displayed next to the switch.


The text color for the switch’s title string. You can also set the switch color using the setColor(_:) method.


The font information to be applied to the title string. You can specify one of the predefined styles or provide custom style information.


Setting the Switch’s Title

func setTitle(String?)

Sets the switch title to the specified string.

func setAttributedTitle(NSAttributedString?)

Sets the switch title to the specified attributed string.

Configuring the Switch

func setOn(Bool)

Sets the state of the switch to the specified value.

func setColor(UIColor?)

Changes the tint color of the switch when it is on.

Enabling the Switch

func setEnabled(Bool)

Enables or disables the switch.


Inherits From

Conforms To

See Also


class WKInterfaceLabel

An interface element that displays static text.

class WKInterfaceDate

A label that displays the current date or time.

class WKInterfaceTimer

A label that displays a countdown or count-up timer.

class WKInterfaceButton

A button in the user interface of your watchOS app.

class WKInterfacePaymentButton

A button that you can use to trigger payments through Apple Pay.

class WKInterfaceSlider

An interface element that lets users select a single floating-point value from a range of values.

class WKInterfaceActivityRing

A view that displays data from a HealthKit activity summary object.

class WKInterfaceMap

An interface element that displays a noninteractive map for the location you specify.