Getting this error Ambiguous use of 'text'












-1














I have created plants entity in firebase db, I want to add another value of "plantId" for some functionality. For this I am creating an random string id and passing it to plant object to be saved in db, but I am getting an error 'Ambiguous use of 'text'. I searched a lot but can't find any solution. please check my code below:



let plantId = NSUUID().uuidString
let plant = ["plantName": self.plantNameField.text, "plantType": self.plantTypeField.text, "plantLocation": self.plantLocationField.text,"userId": userID, "plantImageURL": plantImageURL, "plantId": plantId]
let childUpdates = ["/plants/(key)": plant]
self.ref.updateChildValues(childUpdates)


Error occurring in above code line number 2










share|improve this question





























    -1














    I have created plants entity in firebase db, I want to add another value of "plantId" for some functionality. For this I am creating an random string id and passing it to plant object to be saved in db, but I am getting an error 'Ambiguous use of 'text'. I searched a lot but can't find any solution. please check my code below:



    let plantId = NSUUID().uuidString
    let plant = ["plantName": self.plantNameField.text, "plantType": self.plantTypeField.text, "plantLocation": self.plantLocationField.text,"userId": userID, "plantImageURL": plantImageURL, "plantId": plantId]
    let childUpdates = ["/plants/(key)": plant]
    self.ref.updateChildValues(childUpdates)


    Error occurring in above code line number 2










    share|improve this question



























      -1












      -1








      -1







      I have created plants entity in firebase db, I want to add another value of "plantId" for some functionality. For this I am creating an random string id and passing it to plant object to be saved in db, but I am getting an error 'Ambiguous use of 'text'. I searched a lot but can't find any solution. please check my code below:



      let plantId = NSUUID().uuidString
      let plant = ["plantName": self.plantNameField.text, "plantType": self.plantTypeField.text, "plantLocation": self.plantLocationField.text,"userId": userID, "plantImageURL": plantImageURL, "plantId": plantId]
      let childUpdates = ["/plants/(key)": plant]
      self.ref.updateChildValues(childUpdates)


      Error occurring in above code line number 2










      share|improve this question















      I have created plants entity in firebase db, I want to add another value of "plantId" for some functionality. For this I am creating an random string id and passing it to plant object to be saved in db, but I am getting an error 'Ambiguous use of 'text'. I searched a lot but can't find any solution. please check my code below:



      let plantId = NSUUID().uuidString
      let plant = ["plantName": self.plantNameField.text, "plantType": self.plantTypeField.text, "plantLocation": self.plantLocationField.text,"userId": userID, "plantImageURL": plantImageURL, "plantId": plantId]
      let childUpdates = ["/plants/(key)": plant]
      self.ref.updateChildValues(childUpdates)


      Error occurring in above code line number 2







      ios swift firebase firebase-realtime-database






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 28 '18 at 6:12









      Frank van Puffelen

      227k28372396




      227k28372396










      asked Dec 27 '18 at 21:47









      Huzaifa ameen

      336




      336
























          2 Answers
          2






          active

          oldest

          votes


















          1














          You have not given enough information, but let's assume your code looks like this. You have an outlet:



          @IBOutlet var plantNameField : UITextField!


          And then you say, for example:



          let plantId = NSUUID().uuidString
          let plant = ["plantName": self.plantNameField.text, "plantId":plantId]


          That is illegal because self.plantNameField.text and plantId have different types, whereas a dictionary in Swift must have values of the same type. To fix it, you would say:



          let plant = ["plantName": self.plantNameField.text!, "plantId":plantId]


          (Note the exclamation mark.)



          And similarly for your other text entries in the dictionary.



          But of course this answer is contingent on the guess that plantNameField is indeed a UITextField; you have not shown enough code for me to know whether that is true.






          share|improve this answer























          • Thanks matt! it worked for me.
            – Huzaifa ameen
            Dec 28 '18 at 18:04



















          1














          I think you are missing the creation of the "key"



              let key = ref.child("posts").childByAutoId().key
          let post = ["uid": userID,
          "author": username,
          "title": title,
          "body": body]
          let childUpdates = ["/posts/(key)": post,
          "/user-posts/(userID)/(key)/": post]
          ref.updateChildValues(childUpdates)


          Maybe you already did but take a look at this. https://firebase.google.com/docs/database/ios/read-and-write
          The "Key" creation is the only part that is missing.






          share|improve this answer





















            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%2f53951203%2fgetting-this-error-ambiguous-use-of-text%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            You have not given enough information, but let's assume your code looks like this. You have an outlet:



            @IBOutlet var plantNameField : UITextField!


            And then you say, for example:



            let plantId = NSUUID().uuidString
            let plant = ["plantName": self.plantNameField.text, "plantId":plantId]


            That is illegal because self.plantNameField.text and plantId have different types, whereas a dictionary in Swift must have values of the same type. To fix it, you would say:



            let plant = ["plantName": self.plantNameField.text!, "plantId":plantId]


            (Note the exclamation mark.)



            And similarly for your other text entries in the dictionary.



            But of course this answer is contingent on the guess that plantNameField is indeed a UITextField; you have not shown enough code for me to know whether that is true.






            share|improve this answer























            • Thanks matt! it worked for me.
              – Huzaifa ameen
              Dec 28 '18 at 18:04
















            1














            You have not given enough information, but let's assume your code looks like this. You have an outlet:



            @IBOutlet var plantNameField : UITextField!


            And then you say, for example:



            let plantId = NSUUID().uuidString
            let plant = ["plantName": self.plantNameField.text, "plantId":plantId]


            That is illegal because self.plantNameField.text and plantId have different types, whereas a dictionary in Swift must have values of the same type. To fix it, you would say:



            let plant = ["plantName": self.plantNameField.text!, "plantId":plantId]


            (Note the exclamation mark.)



            And similarly for your other text entries in the dictionary.



            But of course this answer is contingent on the guess that plantNameField is indeed a UITextField; you have not shown enough code for me to know whether that is true.






            share|improve this answer























            • Thanks matt! it worked for me.
              – Huzaifa ameen
              Dec 28 '18 at 18:04














            1












            1








            1






            You have not given enough information, but let's assume your code looks like this. You have an outlet:



            @IBOutlet var plantNameField : UITextField!


            And then you say, for example:



            let plantId = NSUUID().uuidString
            let plant = ["plantName": self.plantNameField.text, "plantId":plantId]


            That is illegal because self.plantNameField.text and plantId have different types, whereas a dictionary in Swift must have values of the same type. To fix it, you would say:



            let plant = ["plantName": self.plantNameField.text!, "plantId":plantId]


            (Note the exclamation mark.)



            And similarly for your other text entries in the dictionary.



            But of course this answer is contingent on the guess that plantNameField is indeed a UITextField; you have not shown enough code for me to know whether that is true.






            share|improve this answer














            You have not given enough information, but let's assume your code looks like this. You have an outlet:



            @IBOutlet var plantNameField : UITextField!


            And then you say, for example:



            let plantId = NSUUID().uuidString
            let plant = ["plantName": self.plantNameField.text, "plantId":plantId]


            That is illegal because self.plantNameField.text and plantId have different types, whereas a dictionary in Swift must have values of the same type. To fix it, you would say:



            let plant = ["plantName": self.plantNameField.text!, "plantId":plantId]


            (Note the exclamation mark.)



            And similarly for your other text entries in the dictionary.



            But of course this answer is contingent on the guess that plantNameField is indeed a UITextField; you have not shown enough code for me to know whether that is true.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Dec 27 '18 at 22:58

























            answered Dec 27 '18 at 22:30









            matt

            324k45522722




            324k45522722












            • Thanks matt! it worked for me.
              – Huzaifa ameen
              Dec 28 '18 at 18:04


















            • Thanks matt! it worked for me.
              – Huzaifa ameen
              Dec 28 '18 at 18:04
















            Thanks matt! it worked for me.
            – Huzaifa ameen
            Dec 28 '18 at 18:04




            Thanks matt! it worked for me.
            – Huzaifa ameen
            Dec 28 '18 at 18:04













            1














            I think you are missing the creation of the "key"



                let key = ref.child("posts").childByAutoId().key
            let post = ["uid": userID,
            "author": username,
            "title": title,
            "body": body]
            let childUpdates = ["/posts/(key)": post,
            "/user-posts/(userID)/(key)/": post]
            ref.updateChildValues(childUpdates)


            Maybe you already did but take a look at this. https://firebase.google.com/docs/database/ios/read-and-write
            The "Key" creation is the only part that is missing.






            share|improve this answer


























              1














              I think you are missing the creation of the "key"



                  let key = ref.child("posts").childByAutoId().key
              let post = ["uid": userID,
              "author": username,
              "title": title,
              "body": body]
              let childUpdates = ["/posts/(key)": post,
              "/user-posts/(userID)/(key)/": post]
              ref.updateChildValues(childUpdates)


              Maybe you already did but take a look at this. https://firebase.google.com/docs/database/ios/read-and-write
              The "Key" creation is the only part that is missing.






              share|improve this answer
























                1












                1








                1






                I think you are missing the creation of the "key"



                    let key = ref.child("posts").childByAutoId().key
                let post = ["uid": userID,
                "author": username,
                "title": title,
                "body": body]
                let childUpdates = ["/posts/(key)": post,
                "/user-posts/(userID)/(key)/": post]
                ref.updateChildValues(childUpdates)


                Maybe you already did but take a look at this. https://firebase.google.com/docs/database/ios/read-and-write
                The "Key" creation is the only part that is missing.






                share|improve this answer












                I think you are missing the creation of the "key"



                    let key = ref.child("posts").childByAutoId().key
                let post = ["uid": userID,
                "author": username,
                "title": title,
                "body": body]
                let childUpdates = ["/posts/(key)": post,
                "/user-posts/(userID)/(key)/": post]
                ref.updateChildValues(childUpdates)


                Maybe you already did but take a look at this. https://firebase.google.com/docs/database/ios/read-and-write
                The "Key" creation is the only part that is missing.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Dec 27 '18 at 22:10









                Sinuee Hernández

                825




                825






























                    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.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • 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%2f53951203%2fgetting-this-error-ambiguous-use-of-text%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

                    Mossoró

                    Error while reading .h5 file using the rhdf5 package in R

                    Pushsharp Apns notification error: 'InvalidToken'