How to present iOS UIActionSheet in Swift?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
If you are asking how to present an action sheet in Swift today, the practical answer is to use UIAlertController with the .actionSheet style. UIActionSheet itself is deprecated, so modern iOS code should treat it as historical background rather than the API to write new code against.
Use UIAlertController with .actionSheet
The modern replacement is straightforward:
This is the standard answer on iPhone. It gives you the familiar action-sheet presentation and lets you define default, destructive, and cancel actions.
iPad requires popover configuration
On iPad, an action sheet is presented as a popover. If you call present without configuring the popover anchor, the app can crash at runtime.
For a button-triggered action sheet:
If the action sheet comes from a navigation bar item, set barButtonItem instead:
That iPad-specific requirement is the most common reason action-sheet code works on iPhone and fails elsewhere.
UIActionSheet was the old API
Older Swift and Objective-C examples may show UIActionSheet with a delegate. That is legacy code from before UIAlertController unified alerts and action sheets.
If you are maintaining very old code, you may encounter something like:
The important point is not memorizing the old syntax. It is recognizing that the current platform direction is UIAlertController.
Prefer closure-based handlers over delegate-style branching
UIAlertAction handlers keep action behavior near the action definition. That is cleaner than older delegate methods that required checking button indexes later.
This also makes the code easier to refactor because:
- the action title and behavior stay together
- destructive actions are explicit
- cancel handling becomes almost trivial
In practice, modern action sheets are easier to read and less error-prone than the deprecated delegate-based approach.
Think about presentation context
Action sheets work best for a short list of mutually exclusive actions that apply to the current screen or selected item. If the list is long, deeply hierarchical, or requires explanation, a dedicated screen may be better.
That is not just UI advice. It affects how maintainable the code becomes. A clean action sheet usually has a small number of clearly named actions and minimal branching logic inside each handler.
Common Pitfalls
- Using deprecated
UIActionSheetcode for new development instead ofUIAlertController. - Forgetting to configure
popoverPresentationControlleron iPad. - Putting too many actions into the sheet and making the UI hard to scan.
- Hiding destructive behavior inside a
.defaultaction instead of marking it.destructive. - Trying to present the action sheet from a view controller that is not currently visible.
Summary
- Modern Swift code should present action sheets with
UIAlertControllerand.actionSheet. - Add actions with
UIAlertActionand present from the current view controller. - On iPad, configure the popover anchor with
sourceViewandsourceRectorbarButtonItem. - Treat
UIActionSheetas legacy API history rather than the current solution. - Keep action sheets short, clear, and context-specific.

