When changing a UIImage to information for saving to Firebase I exploit .jpegData(compressionQuality: 0.9)
nonetheless for Picture I get the next errors,
Can not name worth of non-function kind ‘Binding’
Referencing subscript ‘subscript(dynamicMember:)’ requires wrapper ‘Binding’ Insert ‘$’
Worth of kind ‘Picture’ has no dynamic member ‘jpegData’ utilizing key path from root kind ‘Picture’
The best way to save picture from PhotosPicker?
Code:
import PhotosUI
import SwiftUI
struct ContentView: View {
@State non-public var avatarItem: PhotosPickerItem?
@State non-public var avatarImage: Picture?
var physique: some View {
VStack {
PhotosPicker("Choose avatar", choice: $avatarItem, matching: .pictures)
avatarImage?
.resizable()
.scaledToFit()
.body(width: 300, peak: 300)
}
.onChange(of: avatarItem) {
Job {
if let loaded = attempt? await avatarItem?.loadTransferable(kind: Picture.self) {
avatarImage = loaded
} else {
print("Failed")
}
}
}
}
}
func add() {
if let information = avatarImage.jpegData(compressionQuality: 0.9) { //ERROR HERE
//Add
}
}