title: SwiftUI - How to handle camera permissions?
body: <p>My ImagePicker works as expected. However, I'm trying to implement camera permission handling and I seem to have gotten stuck. I am receiving the error: &quot;Missing return in function expected return UIImagePickerController&quot; and rightfully so. I am not sure where else I can put the switch statement to carry out the handling. Any help is appreciated.</p>
  <pre><code>struct ImagePicker: UIViewControllerRepresentable {
      
      var sourceType: UIImagePickerController.SourceType = .photoLibrary
      
      @Binding var selectedImage: UIImage
      @Binding var alertCameraAccessNeeded: Bool
      @Environment(\.presentationMode) private var presentationMode
      @EnvironmentObject private var userManager: UserManager
      
      let cameraAuthStatus = AVCaptureDevice.authorizationStatus(for: .video)
      
      func makeUIViewController(context: UIViewControllerRepresentableContext&lt;ImagePicker&gt;) -&gt; UIImagePickerController {
          
          switch cameraAuthStatus {
          case .notDetermined: requestCameraPermission()
          case .authorized:
              
              let imagePicker = UIImagePickerController()
              imagePicker.delegate = context.coordinator
              imagePicker.allowsEditing = true
              imagePicker.sourceType = sourceType
              
              return imagePicker
              
          case .restricted, .denied: self.alertCameraAccessNeeded = true
              
          @unknown default:
              fatalError()
          }
          
          
      }
      
      func requestCameraPermission() {
          AVCaptureDevice.requestAccess(for: .video, completionHandler: {accessGranted in
              guard accessGranted == true else { return }
              
          })
      }
      
      func makeCoordinator() -&gt; Coordinator {
          Coordinator(self, userManager: userManager)
      }
      
      
      func updateUIViewController(_ uiViewController: UIImagePickerController, context: UIViewControllerRepresentableContext&lt;ImagePicker&gt;) {
          
      }
      
      
      class Coordinator: NSObject, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
          
          let parent: ImagePicker
          let userManager: UserManager
          
          
          init(_ parent: ImagePicker, userManager: UserManager) {
              self.parent = parent
              self.userManager = userManager
          }
          
          func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
              
              if let image = info[.editedImage] as? UIImage {
                  parent.selectedImage = image
                  userManager.uploadProfilePicture(image: image)
              }
              
              
              parent.presentationMode.wrappedValue.dismiss()
          }
      }
  }
  </code></pre>