<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.1.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UISwitch/setOn(_:animated:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)UISwitch(im)setOn:animated:"
  },
  "title" : "setOn(_:animated:)"
}
-->

# setOn(_:animated:)

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

```
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

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

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)