Isn't there no way to set the default filename to use when we want to save a DataRepresentation to a file?
If I export to JSON, the filename is "JSON.json" is used by iOS, even if I set the name to use in SharePreview.
struct ContentView: View {
let car = Car(id: UUID(), name: "911", items:
[Item(id: UUID(),date: .now, desc: "oil change"),
Item(id: UUID(),date: .now, desc: "Battery")])
var body: some View {
VStack {
ShareLink(item: car, preview: SharePreview(car.name))
}
.padding()
}
}
extension UTType {
static var car: UTType = UTType(exportedAs: "com.acme.cararchive")
}
struct Car: Codable {
let id: UUID
let name: String
let items: [Item]
}
extension Car: Transferable {
static var transferRepresentation: some TransferRepresentation {
DataRepresentation(contentType: .json) { archive in
try JSONEncoder().encode(archive)
} importing: { data in
try JSONDecoder().decode(Car.self, from: data)
}
}
}
struct Item: Codable {
let id: UUID
let date: Date
let desc: String
}
Meet Transferable
RSS for tagDiscuss the WWDC22 Session Meet Transferable
Posts under wwdc2022-10062 tag
2 Posts
Sort by:
Post
Replies
Boosts
Views
Activity
Overview
I am bit confused regarding drag and drop on SwiftUI
I think there are 2 approaches but I am stuck with both approaches
WWDC22
When using the new draggable, dropDestination, Transferable API, only single items are draggable. Multiple items in a list are not draggable. I have filed a feedback FB10128110
WWDC21
I have faced a couple of issues for drag and drop introduced in WWDC21 (onDrag, onDrop, itemIdentifier), the Feedback ids are FB9854301, FB9854569, FB9855245, FB9855532, FB9855567, FB9855575. It contains sample projects, would really appreciate if someone could have a look it.
Note: All feedbacks include a sample project with detail steps and some even have screenshots and videos
Questions:
If my approach is wrong or if I am missing something?
Unfortunately I didn't manage to get a SwiftUI lab session (got cancelled), so please help me with these issues.