<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSSegmentedControl/selectSegment(withTag:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSSegmentedControl(im)selectSegmentWithTag:"
  },
  "title" : "selectSegment(withTag:)"
}
-->

# selectSegment(withTag:)

Selects the segment with the specified tag.

```
func selectSegment(withTag tag: Int) -> Bool
```

## Parameters

`tag`

The tag associated with the desired segment. A tag is an integer value that can be assigned to a segment as a way of identifying it without knowing its position in the control.

## Return Value

<doc://com.apple.documentation/documentation/Swift/true> if the segment was selected successfully; otherwise, <doc://com.apple.documentation/documentation/Swift/false>.

## Discussion

Typically, you use Interface Builder to specify the tag for each segment. You may also set this value programmatically using the `setTag:forSegment:` method of `NSSegmentedCell`.

## See Also

[`setTag(_:forSegment:)`](/documentation/AppKit/NSSegmentedCell/setTag(_:forSegment:))

Sets the tag for the specified segment.



---

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)