Post

Replies

Boosts

Views

Activity

Reply to How to use the .onMove SwiftUI modifier to reorder SwiftData elements?
Attaching it to ForEach works for me. .onMove { source, destination in var tempItems = items tempItems.move(fromOffsets: source, toOffset: destination) for (index, tempItem) in tempItems.enumerated() { if let item = items.filter({ $0.id == tempItem.id}).first { item.orderIndex = index } } } Model: final class Item { var orderIndex: Int? init() { self.orderIndex = nil } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Mar ’24