Getting this error Ambiguous use of 'text'
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
add a comment |
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
add a comment |
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
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
ios swift
edited Dec 28 '18 at 6:12
Frank van Puffelen
227k28372396
227k28372396
asked Dec 27 '18 at 21:47
Huzaifa ameen
336
336
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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.
Thanks matt! it worked for me.
– Huzaifa ameen
Dec 28 '18 at 18:04
add a comment |
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.
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
Thanks matt! it worked for me.
– Huzaifa ameen
Dec 28 '18 at 18:04
add a comment |
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.
Thanks matt! it worked for me.
– Huzaifa ameen
Dec 28 '18 at 18:04
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Dec 27 '18 at 22:10
Sinuee Hernández
825
825
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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