UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Ultimate Portfolio App: Custom sorting for items - alternative approach

Forums > Articles

@cgaaf  

Just posting my alternative approach to the ActionSheet for the Ultimate Portfolio App: Custom sorting for items chapter. I'm accepting of any and all feedback about this approach.

Instead of using the ActionSheet I've opted to use a Menu view to select the sort order. It appears that Apple may be moving in this direction for the design of their own apps. Please refer to how Apple uses a Menu instead of an ActionSheet on the reminders app (Reminders app menu example).

This approach also means that you can use one fewer @State property and directly manage the sort order through a picker.

Here is my approach

@State private var sortOrder = Item.SortOrder.optimized

...

.toolbar {
    ToolbarItem(placement: .primaryAction) {
        if showClosedProjects == false {
            Button {
                withAnimation {
                    dataController.createProject()
                }
            } label: {
                Label("New Project", systemImage: "plus")
            }
        }
    }

    ToolbarItem(placement: .navigationBarLeading) {
        Menu {
            Picker(selection: $sortOrder, label: Text("Sort items")) {
                Text("Optimized").tag(Item.SortOrder.optimized)
                Text("Creation Date").tag(Item.SortOrder.creationDate)
                Text("Title").tag(Item.SortOrder.title)
            }
        } label: {
            Label("Sort", systemImage: "arrow.up.arrow.down")
        }
    }
}

5      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.