I am loading a video from the user's photo library. I want to track the progress of loadTransferable to update a progress view. However, I am having a ton of trouble observing the key values.
I have tried creating an observable object as well, but I can never get the code in the observe closure to run.
Does anyone have any ideas? Thanks in advance :)
import SwiftUI
import Photos
import PhotosUI
struct ContentView: View {
@State private var selectedVideo: PhotosPickerItem?
@State private var observation: NSKeyValueObservation?
private func processSelectedVideo() {
let progress = selectedVideo!.loadTransferable(type: Data.self) { result in
Task {
// do something
}
}
observation = progress.observe(\.fractionCompleted, changeHandler: { progress, value in
// this never runs
print(value)
})
progress.resume()
}
}