---
title: "setOn(_:animated:)"
framework: uikit
role: symbol
role_heading: Instance Method
path: "uikit/uiswitch/seton(_:animated:)"
---

# setOn(_:animated:)

Sets the state of the switch to the on or off position, optionally animating the transition.

## Declaration

```swift
func setOn(_ on: Bool, animated: Bool)
```

## Parameters

- `on`: doc://com.apple.documentation/documentation/Swift/true if the switch should be turned to the on position; doc://com.apple.documentation/documentation/Swift/false if it should be turned to the off position. If the switch is already in the designated position, nothing happens.
- `animated`: doc://com.apple.documentation/documentation/Swift/true to animate the “flipping” of the switch; otherwise doc://com.apple.documentation/documentation/Swift/false.

## Discussion

Discussion Setting the switch to either position doesn’t result in an action message being sent.

## See Also

### Setting the on/off state

- [isOn](uikit/uiswitch/ison.md)
