Hi everyone, I apologize if this has been posted, but I can’t figure out Lesson 5: Camera even with the helpful hints. The issue is that by following the training video, the parameters for the commands are different than for swift 4 and I don’t know how to complete them or if they are even the right ones…
//
// MainTabBarController.swift
// Photo App
//
// Created by Mike Nelson on 1/28/20.
// Copyright © 2020 CIC Solutions. All rights reserved.
//
import UIKit
protocol ImagePickerDelegate: class {
func didselect(image: UIImage?)
}
class MainTabBarController: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
if item.tag == 1 {
// Then the Add tab is selected
// Show the action sheet
showActionSheet()
}
}
func showActionSheet() {
// Create action sheet
var actionSheet = UIAlertController(title: "Add Photo", message: "Select a source:", preferredStyle: .actionSheet)
// Create actions
let pickerController = UIImagePickerController()
pickerController.delegate = self
pickerController.sourceType = .camera
if UIImagePickerController.isSourceTypeAvailable(.camera) {
let cameraAction = UIAlertAction(title: "Camera", style: .default) { (action) in
HERE IS WHERE EVERYTHING STARTS GOING TO YOU KNOW WHERE…
self.showImagePicker(, didFinishPickingMediaWithInfo: <#T##[UIImagePickerController.InfoKey : Any]#>)
}
actionSheet.addAction(cameraAction)
}
if UIImagePickerController.isSourceTypeAvailable(.photoLibrary) {
let libraryAction = UIAlertAction(title: "Photo Library", style: .default) { (action) in
self.showImagePicker(.photoLibrary)
}
actionSheet.addAction(libraryAction)
}
// Present the action sheet
}
}
extension MainTabBarController:UIImagePickerControllerDelegate, UINavigationControllerDelegate {
func showImagePicker(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) {
if let selectedImage = info[UIImagePickerController.InfoKey.originalImage] as? UIImage {
// Get a reference to the camera vc
let cameraVC = self.selectedViewController as? CameraViewController
if let cameraVC = cameraVC {
cameraVC.savePhoto(image: selectedImage)
}
}
}
}
any guidance to get past this step would be great.