It seems that your code doesn't use any Vision Framework features, at least not yet. Removing the Vision import doesn't change anything to your current code. Perhaps you want to add some Vision-related features later?
I tried to run your code, and I only had to make some small changes in your ImagePicker since PresentationMode was deprecated:
struct ImagePicker: UIViewControllerRepresentable {
@Environment(\.dismiss) private var dismiss
@Binding var image: UIImage?
func makeUIViewController(context: Context) -> UIImagePickerController {
let picker = UIImagePickerController()
picker.delegate = context.coordinator
return picker
}
func updateUIViewController(_ uiViewController: UIImagePickerController, context: Context) {}
func makeCoordinator() -> Coordinator {
Coordinator(self)
}
class Coordinator: NSObject, UINavigationControllerDelegate, UIImagePickerControllerDelegate {
var parent: ImagePicker
init(_ parent: ImagePicker) {
self.parent = parent
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) {
if let uiImage = info[.originalImage] as? UIImage {
parent.image = uiImage
}
parent.dismiss()
}
}
}
Everything seemed to work as expected after that. I was able to pick an image and it was displayed in the ContentView.
Also, if you want a SwiftUI Photo Picker implementation (i.e. doesn't rely on UIKit / UIViewControllerRepresentable), you can find out how to do it in this WWDC22 Session video and sample code. But your ImagePicker seems to work fine too.
Topic:
Developer Tools & Services
SubTopic:
Swift Playground
Tags: