TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

Can table or list rows be disabled in SwiftUI?

Forums > macOS

I have some data I want to display in a table (in macOS) and a list (in iOS) where certain rows were created elsewhere in the app (and any editing & deleting needs to be done from there), and other rows that were created within the table or list itself (that can be freely edited or deleted). There is a boolean in the data that is true (if the row contents were created outside the current table or list) and false (if they were created in the table or list).

I know I could use use a foreground color that changes on the rows based on the boolean for that row and then trap for things like delete and selection if the boolean is true for the selected line. But before I do that, I was wondering if there is any way to simply disable the lines in the table or list where the boolean is true so they just can't be selected or deleted to begin with? I thought about .disabled() but I'm not seeing any way I could use that in this context.

                    Table(tableData, selection: $selectedLine) {
                        TableColumn("Name") { sampleLine in
                                .foregroundColor(sampleLine.disabled ? .secondary : .primary)
                        TableColumn("Disabled") { sampleLine in
                            Text(sampleLine.disabled ? "true" : "false")
                                .foregroundColor(sampleLine.disabled ? .secondary : .primary)


Decided to just go with the appearance of disabling (with foreground color) and using alerts to let the user know why they can not delete or edit certain rows of the table or list. More work to set up, but worth it. 🙂


Hacking with Swift is sponsored by Superwall.

SPONSORED Superwall lets you build & test paywalls without shipping updates. Run experiments, offer sales, segment users, update locked features and more at the click of button. Best part? It's FREE for up to 250 conversions / mo and the Superwall team builds out 100% custom paywalls – free of charge.

Learn 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.