Just a heads up I'm new to IOS development and Swift in particular. I have created a "Edit Profile Page" in a view controller that is attached to a regular "profile" view controller. On this edit profile view controller, a user can change their profile picture and cover photo. I am having a hard time understanding how to allow the user to upload their photos to firebase after they choose their image and click the "save button", once they click the save button I want it to upload the image and then redirect them to their regular profile view. I have read other articles and watched other tutorials but I am not able to get the result of successfully uploading both images. Here is my code so far with out any calling to upload images to firebase.
import UIKit
import Foundation
import Firebase
import FirebaseDatabase
class NewEditProfileViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
@IBOutlet weak var imageView1: UIImageView!
@IBOutlet weak var imageView2: UIImageView!
var imagePicker = UIImagePickerController()
var imagePicked = 0
var selectedImage1: UIImage?
override func viewDidLoad() {
super.viewDidLoad()
imagePicker.delegate = self
imagePicker.sourceType = .photoLibrary
imagePicker.allowsEditing = true
}
@IBAction func chooseImage1(_ sender: Any) {
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerController.SourceType.photoLibrary){
imagePicked = (sender as AnyObject).tag
present(imagePicker, animated: true)
}
}
@IBAction func chooseImage2(_ sender: Any) {
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerController.SourceType.photoLibrary){
imagePicked = (sender as AnyObject).tag
present(imagePicker, animated: true)
}
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
let pickedImage = info[UIImagePickerController.InfoKey.editedImage] as? UIImage
if imagePicked == 1 {
imageView1.image = pickedImage
} else if imagePicked == 2 {
imageView2.image = pickedImage
}
dismiss(animated: true)
}
func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
dismiss(animated: true)
}
@IBAction func saveButton(_ sender: Any) {
}
@IBAction func backButton(_ sender: Any) {
self.dismiss(animated: true, completion: nil)
}
}
Thank you for the help! Like I said, Swift and Firebase overall is a new concept to me.