1

The question is quite simple. I receive entities from API that contains property actions and I need to display them in a list with actions as swipe actions accordingly.

Problem is that I didn't find the way how to iterate actions in swipeActions modificator.

I tried something like this:

List {
    ForEach(entities) { entity in
        CustomCell(entity: entity)
            .swipeActions(edge: .trailing) {
                for action in entity.actions {
                    Button(action: {}) {
                        Label(action.title)
                    }
                }
            }
    }
}

and it does not work.

Is it even possible to solve?

1 Answer 1

1

Assuming action type is Identifiable (if not then confirm it), it can be done with ForEach, because swipeActions expects views, so it can be like

List {
    ForEach(entities) { entity in
        CustomCell(entity: entity)
            .swipeActions(edge: .trailing) {
                ForEach(entity.actions) { action in    // << here !!
                    Button(action: {}) {
                        Label(action.title)
                    }
                }
            }
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.