---
title: "setMenu(_:forSegment:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nssegmentedcontrol/setmenu(_:forsegment:)"
---

# setMenu(_:forSegment:)

Sets the menu for the specified segment.

## Declaration

```swift
func setMenu(_ menu: NSMenu?, forSegment segment: Int)
```

## Parameters

- `menu`: The menu you want to add to the segment or nil to clear the current menu.
- `segment`: The index of the segment whose menu you want to set. This method raises an exception (doc://com.apple.documentation/documentation/Foundation/NSExceptionName/rangeException) if the index is out of bounds.

## Discussion

Discussion Adding a menu to a segment allows the segment to be used as a pop-up button. If the segment has a menu only, then the menu displays when the user clicks the segment. If the segment has both a menu and an action, then the action triggers when the user clicks the segment and the menu displays when the user clicks and holds the segment.

## See Also

### Configuring a segment menu

- [menu(forSegment:)](appkit/nssegmentedcontrol/menu(forsegment:).md)
- [setShowsMenuIndicator(_:forSegment:)](appkit/nssegmentedcontrol/setshowsmenuindicator(_:forsegment:).md)
- [showsMenuIndicator(forSegment:)](appkit/nssegmentedcontrol/showsmenuindicator(forsegment:).md)
- [isSpringLoaded](appkit/nssegmentedcontrol/isspringloaded.md)
