     private var captionText: String!
     
     var feed: FeedItem?
+    var image : UIImage?
+    
     
     
     override func viewDidLoad() {
         super.viewDidLoad()
-
+        
         captionTextField.delegate = self
         doneButton.isEnabled = false
     }
-
+    
     override func didReceiveMemoryWarning() {
         super.didReceiveMemoryWarning()
         // Dispose of any resources that can be recreated.
     }
-
-    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
-        super.prepare(for: segue, sender: sender)
+    
+    @IBAction func done(_ sender: UIBarButtonItem) {
         
-        guard let button = sender as? UIBarButtonItem, button === doneButton else {
-            os_log("The done button was not pressed", log: .default, type: .debug)
-            return
-        }
-        
-        let caption = captionTextField.text ?? ""
-        
-        guard let uid = FIRAuth.auth()?.currentUser?.uid else {
-            return
-        }
-        
-        let currentDateTime = Date()
-        
-        // initialize the date formatter and set the style
-        let formatter = DateFormatter()
-        formatter.timeStyle = .medium
-        formatter.dateStyle = .long
-        
-        // get the date time String from the date object
-        formatter.string(from: currentDateTime)
-        
-        if photoImageView.image != nil {
-            
-            Model.instance.saveImage(image: photoImageView.image!, name:self.captionText){(url) in
+        if image != nil {
+            Model.instance.saveImage(image: image!) {(url) in
                 
-                let feed = FeedItem(id: "", userId: uid, author: (FIRAuth.auth()?.currentUser?.displayName)!, date: currentDateTime, imageUrl: url!, location: caption, likesCount: 0, isLikeClicked: false)
+                let caption = self.captionTextField.text ?? ""
+                let currentDateTime = Date()
                 
-                Model.instance.addFeedItem(fi: feed)
+                // initialize the date formatter and set the style
+                let formatter = DateFormatter()
+                formatter.timeStyle = .medium
+                formatter.dateStyle = .long
+                
+                // get the date time String from the date object
+                formatter.string(from: currentDateTime)
+                
+                let feedItem = FeedItem(id: "",userId: (Model.instance.currentUser?.id)!, author: (Model.instance.currentUser?.name)!, date: currentDateTime, imageUrl: url!, location: caption, likesCount: 0, isLikeClicked: false)
+                
+                Model.instance.addFeedItem(fi: feedItem)
                 
                 self.navigationController!.popViewController(animated: true)
             }
+        }else{
+            self.navigationController!.popViewController(animated: true)
         }
     }
+
     
     @IBAction func cancel(_ sender: UIBarButtonItem) {
         dismiss(animated: true, completion: nil)
     }
-
+    
     
     //MARK: UITextFieldDelegate
     

import os.log

class UploadPhotoViewController: UIViewController , UITextFieldDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate {

    //MARK: Properties
    
    @IBOutlet weak var captionTextField: UITextField!

        present(imagePickerController, animated: true, completion: nil)
    }
    
    
    func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
        dismiss(animated: true, completion: nil)
    }
