M3 L5 swift 5 not working

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.

It would be better to zip or compress your project so we can take a look at it… rather than posting all the codes here

OK, I’m not familiar with this process, my apologies. When I click on the upload file, I can’t upload a .zip. Now what?

Mike

Upload it in a file sharing service or maybe cloud or onedrive then post the link here

OK I’ve created a public box folder here https://app.box.com/s/7hvnloar9zam031h1xtsdb7duxs7gj5e and hopefully I created it correctly and you can see the .zip file

i took a look at your project and built it but i see no errors (red errors)

did you open the .xcworkspace?

thats the one you should open not the .xcproj

Thanks for your help. I moved on to Realm and completed those two modules first. Now I have gone back, and am able to correct my original errors (I think I erased the code that I had put in before I zipped it. Sorry for wasting your time!)

Regards - Mike

1 Like

no worries! glad you got it sorted out :slight_smile: