Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
extension ContentView {
final class ViewModel: ObservableObject {
@Published var selectedImage: UIImage?
@Published var isPresentingImagePicker = false
private(set) var sourceType: ImagePicker.SourceType = .camera
func choosePhoto() {
sourceType = .photoLibrary
isPresentingImagePicker = true
}
func takePhoto() {
sourceType = .camera
isPresentingImagePicker = true
}
func didSelectImage(_ image: UIImage?) {
selectedImage = image
isPresentingImagePicker = false
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment