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
}