IanLock00
IanLock00

Reputation: 21

SWIFTUI: Filtering Lists

I am creating a task management app for my school project, and have hit a wall. My app is based off of the Scrumdinger Tutorial from my Apple to give context. I am currently trying to figure out how to filter items in the list based on two boolean values I have set for task completion, and being delted.

My tasks are structured as followed: enter image description here

As you can see I've add the two different boolean variables that change based on button clicks within the detailView of the task.

The List of tasks is currently organized in this format, and I'm not exactly sure how to filter based on those value's within the List. enter image description here

Tasks are stored here: enter image description here

Any Help would be greatly appreciated!

Upvotes: 0

Views: 3873

Answers (1)

Duc Dang
Duc Dang

Reputation: 186

You can try this simple solution and apply your own button logical, as you want

struct Object: Identifiable, Codable {
    var id = UUID()
    var taskDone: Bool
    var text: String
}

@State var array = [Object(taskDone: true, text: "taskDone1"), Object(taskDone: false, text: "taskDone2")]

    var body: some View {
                List(array.filter { $0.taskDone }){ (item) in
                    Text("\(item.text)")
                        .foregroundColor(.red)
            }
    }

Upvotes: 1

Related Questions