|
I have not found an example where drag and drop can be used to "move" a Table row using the newer Transferable protocol. Anyone have some sample code? If not doable, is this coming to Table in the future? Essentially, dnd is a gesture to reassign a property value which results in a refiguring of the Table. I have a Table of hierarchical SwiftData objects and want the user to be able to "drop" the row between children in a new family or on a row, thus triggering an update to the parent property. |
|
Based on the sparse examples I have found, I thought this would work but it does not compile:
Still looking for working example code and insights. Thanks. |
|
Making some progress, thanks in part to https://www.youtube.com/watch?v=lsXqJKm4l-U&t=1100s (Using Xcode 15.3, coding an exclusively MacOS app) In my .app file:
where com.....account is an Exported Type Identifier specified in the project Info tab In my object file we add conformance with Transferable (it's already in conformance with Codable):
then in the view with the Table:
The rows are draggable. A row highlights when targeted as a destination. The app hangs with no errors on drop. Drag and Drop to nowhere is tolerated (dragged item snaps back). In the TableRowContent documentation example there is In the Sean Allen example noted above there is also a "return true", which also stops compilation when I add it. Aside, I had to remove one of the return values from .dropDestination and I'm guessing that should be "destination"--a place on screen--and not the set of dropped items. So half-way there. Why does the drop not exit gracefully (there's nothing to do yet, a print() statement is never reached before the hang). What am I missing? |
|
Despite thinking I've made my whole SwiftData object Transferable and expecting that to be adequate I've resorted to passing a String instead of my object.
Still only one returned argument, adding true to return or adding isTargeted:{} prevented compliation. Since my objects all have unique names it's simpler to drop a set of names.
Since I use this dropDestination modifier several times I have tried but failed to abstract this code. While in a struct as described in https://www.hackingwithswift.com/books/ios-swiftui/custom-modifiers compiler wants the usual two return arguments and "return true". Probably needs to be a specific TableRow return view.
|
|
Unless you want to stick with In this tutorial, you can append |
SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.
Sponsor Hacking with Swift and reach the world's largest Swift community!
You need to create an account or log in to reply.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.