Join our newsletter! Get Swift & SwiftUI tips, project updates, and discounts on our books...JOIN OUR NEWSLETTER!Monthly Swift insights, updates, and deals...
Quick Tip Icon
Quick Tip

ControlGroup in context menus in SwiftUI

Starting from iOS 17 and iPadOS 17 we can now use a ControlGroup inside a contextMenu(), enabling more compact access to common actions.

Screenshot of a context menu open showing cut, copy and past all in a horizontal stack.
ContentView()
    .contextMenu {
        ControlGroup {
            Button {
                // cut action
            } label: {
                Label("Cut", systemImage: "scissors")
            }
            
            Button {
                // copy action
            } label: {
                Label("Copy", systemImage: "doc.on.doc")
            }
            
            Button {
                // paste action
            } label: {
                Label("Paste", systemImage: "doc.on.clipboard")
            }
        }
        
        Button(role: .destructive) {
            // delete action
        } label: {
            Label("Delete", systemImage: "trash")
        }
    }

On macOS this code creates a nested sub-menu with cut, copy and paste as items.

Swift Gems by Natalia Panferova book coverSwift Gems by Natalia Panferova book cover

Level up your Swift skills!$35

100+ tips to take your Swift code to the next level

Swift Gemsby Natalia Panferova

  • Advanced Swift techniques for experienced developers bypassing basic tutorials
  • Curated, actionable tips ready for immediate integration into any Swift project
  • Strategies to improve code quality, structure, and performance across all platforms

Level up your Swift skills!

100+ tips to take your Swift code to the next level

Swift Gems by Natalia Panferova book coverSwift Gems by Natalia Panferova book cover

Swift Gems

by Natalia Panferova

$35