iOS Firebase - Problem to get the photo's url (Unresolved identifier)












0















Im trying to get the url of the photo which the user selects and then send it to Firebase. Im getting this error in the last line:
Use of unresolved identifier 'profileImageUrl'; did you mean 'profileImage'?



@IBAction func signUpBtn(_ sender: Any) {
Auth.auth().createUser(withEmail: emailTextField.text!, password: passwordTextField.text!, completion: { (user, error) in
if error != nil {
print("error")
return
}


let storageRef = Storage.storage().reference(forURL: "gs://justforpractice.appspot.com").child("profile_image").child(userID)
if let profileImg = self.selectedImage, let imageData = self.selectedImage?.jpegData(compressionQuality: 0.1){
storageRef.putData(imageData, metadata: nil, completion: { (metadata, error) in
if error != nil {
return
}


storageRef.downloadURL { (url, error) in
guard let profileImageUrl = url else {
// An error occurred!
return
}
}

let ref = Database.database().reference()
let usersReference = ref.child("users")
let newUserReference = usersReference.child(userID)
newUserReference.setValue(["username": self.usernameTextField.text!, "email": self.emailTextField.text!, "profileImageUrl": profileImageUrl])

})
}
})
}









share|improve this question





























    0















    Im trying to get the url of the photo which the user selects and then send it to Firebase. Im getting this error in the last line:
    Use of unresolved identifier 'profileImageUrl'; did you mean 'profileImage'?



    @IBAction func signUpBtn(_ sender: Any) {
    Auth.auth().createUser(withEmail: emailTextField.text!, password: passwordTextField.text!, completion: { (user, error) in
    if error != nil {
    print("error")
    return
    }


    let storageRef = Storage.storage().reference(forURL: "gs://justforpractice.appspot.com").child("profile_image").child(userID)
    if let profileImg = self.selectedImage, let imageData = self.selectedImage?.jpegData(compressionQuality: 0.1){
    storageRef.putData(imageData, metadata: nil, completion: { (metadata, error) in
    if error != nil {
    return
    }


    storageRef.downloadURL { (url, error) in
    guard let profileImageUrl = url else {
    // An error occurred!
    return
    }
    }

    let ref = Database.database().reference()
    let usersReference = ref.child("users")
    let newUserReference = usersReference.child(userID)
    newUserReference.setValue(["username": self.usernameTextField.text!, "email": self.emailTextField.text!, "profileImageUrl": profileImageUrl])

    })
    }
    })
    }









    share|improve this question



























      0












      0








      0








      Im trying to get the url of the photo which the user selects and then send it to Firebase. Im getting this error in the last line:
      Use of unresolved identifier 'profileImageUrl'; did you mean 'profileImage'?



      @IBAction func signUpBtn(_ sender: Any) {
      Auth.auth().createUser(withEmail: emailTextField.text!, password: passwordTextField.text!, completion: { (user, error) in
      if error != nil {
      print("error")
      return
      }


      let storageRef = Storage.storage().reference(forURL: "gs://justforpractice.appspot.com").child("profile_image").child(userID)
      if let profileImg = self.selectedImage, let imageData = self.selectedImage?.jpegData(compressionQuality: 0.1){
      storageRef.putData(imageData, metadata: nil, completion: { (metadata, error) in
      if error != nil {
      return
      }


      storageRef.downloadURL { (url, error) in
      guard let profileImageUrl = url else {
      // An error occurred!
      return
      }
      }

      let ref = Database.database().reference()
      let usersReference = ref.child("users")
      let newUserReference = usersReference.child(userID)
      newUserReference.setValue(["username": self.usernameTextField.text!, "email": self.emailTextField.text!, "profileImageUrl": profileImageUrl])

      })
      }
      })
      }









      share|improve this question
















      Im trying to get the url of the photo which the user selects and then send it to Firebase. Im getting this error in the last line:
      Use of unresolved identifier 'profileImageUrl'; did you mean 'profileImage'?



      @IBAction func signUpBtn(_ sender: Any) {
      Auth.auth().createUser(withEmail: emailTextField.text!, password: passwordTextField.text!, completion: { (user, error) in
      if error != nil {
      print("error")
      return
      }


      let storageRef = Storage.storage().reference(forURL: "gs://justforpractice.appspot.com").child("profile_image").child(userID)
      if let profileImg = self.selectedImage, let imageData = self.selectedImage?.jpegData(compressionQuality: 0.1){
      storageRef.putData(imageData, metadata: nil, completion: { (metadata, error) in
      if error != nil {
      return
      }


      storageRef.downloadURL { (url, error) in
      guard let profileImageUrl = url else {
      // An error occurred!
      return
      }
      }

      let ref = Database.database().reference()
      let usersReference = ref.child("users")
      let newUserReference = usersReference.child(userID)
      newUserReference.setValue(["username": self.usernameTextField.text!, "email": self.emailTextField.text!, "profileImageUrl": profileImageUrl])

      })
      }
      })
      }






      ios swift firebase






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 22 '18 at 9:25









      wvteijlingen

      8,82912545




      8,82912545










      asked Nov 21 '18 at 19:11









      xfxrxaxnxfxrxaxn

      32




      32
























          1 Answer
          1






          active

          oldest

          votes


















          1














          You should put your code inside the storageRef.downloadUrl closure so you have access to the unwrapped url:



          storageRef.downloadURL { (url, error) in
          guard let profileImageUrl = url else {
          // An error occurred!
          return
          }

          let ref = Database.database().reference()
          let usersReference = ref.child("users")
          let newUserReference = usersReference.child(userID)
          newUserReference.setValue(["username": self.usernameTextField.text!, "email": self.emailTextField.text!, "profileImageUrl": profileImageUrl])
          }





          share|improve this answer
























          • Thank you very much @vasil-garov , its working. Now the url is being saved in the Storage but the data is not in the Database.

            – xfxrxaxn
            Nov 21 '18 at 20:46











          • If I leave the code like this: codeshare.io/5QzmvL I can send the data to the Database but not to the Storage.

            – xfxrxaxn
            Nov 21 '18 at 20:56













          • Well, this is normal - you commented out the storage code.

            – Vasil Garov
            Nov 21 '18 at 21:08











          • Hi Vasil, I commented it just to show you that before I added the code to send the url to the Storage, the data related to the Database used to be sent. Now that I added the code related to the Storage, the data related to the Database is not being send anymore. I don't understand why.

            – xfxrxaxn
            Nov 24 '18 at 11:09













          • Can you show me your current code?

            – Vasil Garov
            Nov 24 '18 at 11:40












          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53419033%2fios-firebase-problem-to-get-the-photos-url-unresolved-identifier%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          You should put your code inside the storageRef.downloadUrl closure so you have access to the unwrapped url:



          storageRef.downloadURL { (url, error) in
          guard let profileImageUrl = url else {
          // An error occurred!
          return
          }

          let ref = Database.database().reference()
          let usersReference = ref.child("users")
          let newUserReference = usersReference.child(userID)
          newUserReference.setValue(["username": self.usernameTextField.text!, "email": self.emailTextField.text!, "profileImageUrl": profileImageUrl])
          }





          share|improve this answer
























          • Thank you very much @vasil-garov , its working. Now the url is being saved in the Storage but the data is not in the Database.

            – xfxrxaxn
            Nov 21 '18 at 20:46











          • If I leave the code like this: codeshare.io/5QzmvL I can send the data to the Database but not to the Storage.

            – xfxrxaxn
            Nov 21 '18 at 20:56













          • Well, this is normal - you commented out the storage code.

            – Vasil Garov
            Nov 21 '18 at 21:08











          • Hi Vasil, I commented it just to show you that before I added the code to send the url to the Storage, the data related to the Database used to be sent. Now that I added the code related to the Storage, the data related to the Database is not being send anymore. I don't understand why.

            – xfxrxaxn
            Nov 24 '18 at 11:09













          • Can you show me your current code?

            – Vasil Garov
            Nov 24 '18 at 11:40
















          1














          You should put your code inside the storageRef.downloadUrl closure so you have access to the unwrapped url:



          storageRef.downloadURL { (url, error) in
          guard let profileImageUrl = url else {
          // An error occurred!
          return
          }

          let ref = Database.database().reference()
          let usersReference = ref.child("users")
          let newUserReference = usersReference.child(userID)
          newUserReference.setValue(["username": self.usernameTextField.text!, "email": self.emailTextField.text!, "profileImageUrl": profileImageUrl])
          }





          share|improve this answer
























          • Thank you very much @vasil-garov , its working. Now the url is being saved in the Storage but the data is not in the Database.

            – xfxrxaxn
            Nov 21 '18 at 20:46











          • If I leave the code like this: codeshare.io/5QzmvL I can send the data to the Database but not to the Storage.

            – xfxrxaxn
            Nov 21 '18 at 20:56













          • Well, this is normal - you commented out the storage code.

            – Vasil Garov
            Nov 21 '18 at 21:08











          • Hi Vasil, I commented it just to show you that before I added the code to send the url to the Storage, the data related to the Database used to be sent. Now that I added the code related to the Storage, the data related to the Database is not being send anymore. I don't understand why.

            – xfxrxaxn
            Nov 24 '18 at 11:09













          • Can you show me your current code?

            – Vasil Garov
            Nov 24 '18 at 11:40














          1












          1








          1







          You should put your code inside the storageRef.downloadUrl closure so you have access to the unwrapped url:



          storageRef.downloadURL { (url, error) in
          guard let profileImageUrl = url else {
          // An error occurred!
          return
          }

          let ref = Database.database().reference()
          let usersReference = ref.child("users")
          let newUserReference = usersReference.child(userID)
          newUserReference.setValue(["username": self.usernameTextField.text!, "email": self.emailTextField.text!, "profileImageUrl": profileImageUrl])
          }





          share|improve this answer













          You should put your code inside the storageRef.downloadUrl closure so you have access to the unwrapped url:



          storageRef.downloadURL { (url, error) in
          guard let profileImageUrl = url else {
          // An error occurred!
          return
          }

          let ref = Database.database().reference()
          let usersReference = ref.child("users")
          let newUserReference = usersReference.child(userID)
          newUserReference.setValue(["username": self.usernameTextField.text!, "email": self.emailTextField.text!, "profileImageUrl": profileImageUrl])
          }






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 21 '18 at 20:01









          Vasil GarovVasil Garov

          3,15811427




          3,15811427













          • Thank you very much @vasil-garov , its working. Now the url is being saved in the Storage but the data is not in the Database.

            – xfxrxaxn
            Nov 21 '18 at 20:46











          • If I leave the code like this: codeshare.io/5QzmvL I can send the data to the Database but not to the Storage.

            – xfxrxaxn
            Nov 21 '18 at 20:56













          • Well, this is normal - you commented out the storage code.

            – Vasil Garov
            Nov 21 '18 at 21:08











          • Hi Vasil, I commented it just to show you that before I added the code to send the url to the Storage, the data related to the Database used to be sent. Now that I added the code related to the Storage, the data related to the Database is not being send anymore. I don't understand why.

            – xfxrxaxn
            Nov 24 '18 at 11:09













          • Can you show me your current code?

            – Vasil Garov
            Nov 24 '18 at 11:40



















          • Thank you very much @vasil-garov , its working. Now the url is being saved in the Storage but the data is not in the Database.

            – xfxrxaxn
            Nov 21 '18 at 20:46











          • If I leave the code like this: codeshare.io/5QzmvL I can send the data to the Database but not to the Storage.

            – xfxrxaxn
            Nov 21 '18 at 20:56













          • Well, this is normal - you commented out the storage code.

            – Vasil Garov
            Nov 21 '18 at 21:08











          • Hi Vasil, I commented it just to show you that before I added the code to send the url to the Storage, the data related to the Database used to be sent. Now that I added the code related to the Storage, the data related to the Database is not being send anymore. I don't understand why.

            – xfxrxaxn
            Nov 24 '18 at 11:09













          • Can you show me your current code?

            – Vasil Garov
            Nov 24 '18 at 11:40

















          Thank you very much @vasil-garov , its working. Now the url is being saved in the Storage but the data is not in the Database.

          – xfxrxaxn
          Nov 21 '18 at 20:46





          Thank you very much @vasil-garov , its working. Now the url is being saved in the Storage but the data is not in the Database.

          – xfxrxaxn
          Nov 21 '18 at 20:46













          If I leave the code like this: codeshare.io/5QzmvL I can send the data to the Database but not to the Storage.

          – xfxrxaxn
          Nov 21 '18 at 20:56







          If I leave the code like this: codeshare.io/5QzmvL I can send the data to the Database but not to the Storage.

          – xfxrxaxn
          Nov 21 '18 at 20:56















          Well, this is normal - you commented out the storage code.

          – Vasil Garov
          Nov 21 '18 at 21:08





          Well, this is normal - you commented out the storage code.

          – Vasil Garov
          Nov 21 '18 at 21:08













          Hi Vasil, I commented it just to show you that before I added the code to send the url to the Storage, the data related to the Database used to be sent. Now that I added the code related to the Storage, the data related to the Database is not being send anymore. I don't understand why.

          – xfxrxaxn
          Nov 24 '18 at 11:09







          Hi Vasil, I commented it just to show you that before I added the code to send the url to the Storage, the data related to the Database used to be sent. Now that I added the code related to the Storage, the data related to the Database is not being send anymore. I don't understand why.

          – xfxrxaxn
          Nov 24 '18 at 11:09















          Can you show me your current code?

          – Vasil Garov
          Nov 24 '18 at 11:40





          Can you show me your current code?

          – Vasil Garov
          Nov 24 '18 at 11:40




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53419033%2fios-firebase-problem-to-get-the-photos-url-unresolved-identifier%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          How to pass form data using jquery Ajax to insert data in database?

          National Museum of Racing and Hall of Fame

          Guess what letter conforming each word