Error while trying to build a send button












0














I'm currently trying to build a chat feature, but I get some errors when trying to implement a send button. The errors I get are:
**




Binary operator '!=' cannot be applied to operands of type 'UITextField?' 'String'




and




Value of type 'DataService' has no member 'createNewMessage'




My code:



@IBAction func sendButton(_ sender: Any) {
self.chatTextfield.resignFirstResponder()
if chatTextfield != "" {
if let user = Auth.auth().currentUser {
DataService.dataService.createNewMessage(user.uid, roomId: roomId, textMessage: chatTextfield.text!)
}
}
}









share|improve this question
























  • Is the DataService class a Firebase class?
    – Rakesha Shastri
    Nov 21 '18 at 13:00










  • @RakeshaShastri yes
    – potatoonion
    Nov 21 '18 at 13:01










  • Is there any documentation for that?
    – Rakesha Shastri
    Nov 21 '18 at 13:05










  • I tried writing DataService.dataservice. but only createNewRoom showed up and not createNewMessage
    – potatoonion
    Nov 21 '18 at 13:08










  • There is no class in the Firebase SDK that has createNewMessage and/or createNewRoom methods, so it seems that you created this class yourself or copied it from somewhere. I recommend opening a new question for this problem (since Rakesha already answered for your other question), and creating a minimal, complete, verifiable example (read the link please, it's quite useful when asking for help with code-related questions) in there.
    – Frank van Puffelen
    Nov 21 '18 at 14:32
















0














I'm currently trying to build a chat feature, but I get some errors when trying to implement a send button. The errors I get are:
**




Binary operator '!=' cannot be applied to operands of type 'UITextField?' 'String'




and




Value of type 'DataService' has no member 'createNewMessage'




My code:



@IBAction func sendButton(_ sender: Any) {
self.chatTextfield.resignFirstResponder()
if chatTextfield != "" {
if let user = Auth.auth().currentUser {
DataService.dataService.createNewMessage(user.uid, roomId: roomId, textMessage: chatTextfield.text!)
}
}
}









share|improve this question
























  • Is the DataService class a Firebase class?
    – Rakesha Shastri
    Nov 21 '18 at 13:00










  • @RakeshaShastri yes
    – potatoonion
    Nov 21 '18 at 13:01










  • Is there any documentation for that?
    – Rakesha Shastri
    Nov 21 '18 at 13:05










  • I tried writing DataService.dataservice. but only createNewRoom showed up and not createNewMessage
    – potatoonion
    Nov 21 '18 at 13:08










  • There is no class in the Firebase SDK that has createNewMessage and/or createNewRoom methods, so it seems that you created this class yourself or copied it from somewhere. I recommend opening a new question for this problem (since Rakesha already answered for your other question), and creating a minimal, complete, verifiable example (read the link please, it's quite useful when asking for help with code-related questions) in there.
    – Frank van Puffelen
    Nov 21 '18 at 14:32














0












0








0







I'm currently trying to build a chat feature, but I get some errors when trying to implement a send button. The errors I get are:
**




Binary operator '!=' cannot be applied to operands of type 'UITextField?' 'String'




and




Value of type 'DataService' has no member 'createNewMessage'




My code:



@IBAction func sendButton(_ sender: Any) {
self.chatTextfield.resignFirstResponder()
if chatTextfield != "" {
if let user = Auth.auth().currentUser {
DataService.dataService.createNewMessage(user.uid, roomId: roomId, textMessage: chatTextfield.text!)
}
}
}









share|improve this question















I'm currently trying to build a chat feature, but I get some errors when trying to implement a send button. The errors I get are:
**




Binary operator '!=' cannot be applied to operands of type 'UITextField?' 'String'




and




Value of type 'DataService' has no member 'createNewMessage'




My code:



@IBAction func sendButton(_ sender: Any) {
self.chatTextfield.resignFirstResponder()
if chatTextfield != "" {
if let user = Auth.auth().currentUser {
DataService.dataService.createNewMessage(user.uid, roomId: roomId, textMessage: chatTextfield.text!)
}
}
}






swift firebase






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 13:02









Rakesha Shastri

6,85921232




6,85921232










asked Nov 21 '18 at 12:52









potatoonion

93




93












  • Is the DataService class a Firebase class?
    – Rakesha Shastri
    Nov 21 '18 at 13:00










  • @RakeshaShastri yes
    – potatoonion
    Nov 21 '18 at 13:01










  • Is there any documentation for that?
    – Rakesha Shastri
    Nov 21 '18 at 13:05










  • I tried writing DataService.dataservice. but only createNewRoom showed up and not createNewMessage
    – potatoonion
    Nov 21 '18 at 13:08










  • There is no class in the Firebase SDK that has createNewMessage and/or createNewRoom methods, so it seems that you created this class yourself or copied it from somewhere. I recommend opening a new question for this problem (since Rakesha already answered for your other question), and creating a minimal, complete, verifiable example (read the link please, it's quite useful when asking for help with code-related questions) in there.
    – Frank van Puffelen
    Nov 21 '18 at 14:32


















  • Is the DataService class a Firebase class?
    – Rakesha Shastri
    Nov 21 '18 at 13:00










  • @RakeshaShastri yes
    – potatoonion
    Nov 21 '18 at 13:01










  • Is there any documentation for that?
    – Rakesha Shastri
    Nov 21 '18 at 13:05










  • I tried writing DataService.dataservice. but only createNewRoom showed up and not createNewMessage
    – potatoonion
    Nov 21 '18 at 13:08










  • There is no class in the Firebase SDK that has createNewMessage and/or createNewRoom methods, so it seems that you created this class yourself or copied it from somewhere. I recommend opening a new question for this problem (since Rakesha already answered for your other question), and creating a minimal, complete, verifiable example (read the link please, it's quite useful when asking for help with code-related questions) in there.
    – Frank van Puffelen
    Nov 21 '18 at 14:32
















Is the DataService class a Firebase class?
– Rakesha Shastri
Nov 21 '18 at 13:00




Is the DataService class a Firebase class?
– Rakesha Shastri
Nov 21 '18 at 13:00












@RakeshaShastri yes
– potatoonion
Nov 21 '18 at 13:01




@RakeshaShastri yes
– potatoonion
Nov 21 '18 at 13:01












Is there any documentation for that?
– Rakesha Shastri
Nov 21 '18 at 13:05




Is there any documentation for that?
– Rakesha Shastri
Nov 21 '18 at 13:05












I tried writing DataService.dataservice. but only createNewRoom showed up and not createNewMessage
– potatoonion
Nov 21 '18 at 13:08




I tried writing DataService.dataservice. but only createNewRoom showed up and not createNewMessage
– potatoonion
Nov 21 '18 at 13:08












There is no class in the Firebase SDK that has createNewMessage and/or createNewRoom methods, so it seems that you created this class yourself or copied it from somewhere. I recommend opening a new question for this problem (since Rakesha already answered for your other question), and creating a minimal, complete, verifiable example (read the link please, it's quite useful when asking for help with code-related questions) in there.
– Frank van Puffelen
Nov 21 '18 at 14:32




There is no class in the Firebase SDK that has createNewMessage and/or createNewRoom methods, so it seems that you created this class yourself or copied it from somewhere. I recommend opening a new question for this problem (since Rakesha already answered for your other question), and creating a minimal, complete, verifiable example (read the link please, it's quite useful when asking for help with code-related questions) in there.
– Frank van Puffelen
Nov 21 '18 at 14:32












1 Answer
1






active

oldest

votes


















1














The first error is because you are comparing UITextField object with a String. You should be comparing the text in the text field instead.



if chatTextfield.text != "" {
// do something
}


Or in a more Swifty way, like this,



if !chatTextfield.text!.isEmpty {
// do something
}


My knowledge in Firebase is next to none. So, i can't help you much with the second one. From the error, it is pretty clear that there is no method by that name. So, if you just got the method signature wrong, you should write DataService.dataService. and let firebase show you suggestions and pick the appropriate one.






share|improve this answer























  • thank you! the first problem got solved. I tried the DataService.dataService. but only createNewRoom showed up and not CreateNewMessage
    – potatoonion
    Nov 21 '18 at 13:07












  • @potatoonion where did you see this createNewMessage method?
    – Rakesha Shastri
    Nov 21 '18 at 13:08










  • I read somewhere yesterday night that's how to create a message guess it was wrong, is there another way to create a message?
    – potatoonion
    Nov 21 '18 at 13:10










  • I'm not familiar with firebase. You should look up their documentation.
    – Rakesha Shastri
    Nov 21 '18 at 13:15










  • yea same, I'm kinda new to firebase too. I don't seem to still understand their documentation about creating new message tho :(
    – potatoonion
    Nov 21 '18 at 13:28













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%2f53412466%2ferror-while-trying-to-build-a-send-button%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














The first error is because you are comparing UITextField object with a String. You should be comparing the text in the text field instead.



if chatTextfield.text != "" {
// do something
}


Or in a more Swifty way, like this,



if !chatTextfield.text!.isEmpty {
// do something
}


My knowledge in Firebase is next to none. So, i can't help you much with the second one. From the error, it is pretty clear that there is no method by that name. So, if you just got the method signature wrong, you should write DataService.dataService. and let firebase show you suggestions and pick the appropriate one.






share|improve this answer























  • thank you! the first problem got solved. I tried the DataService.dataService. but only createNewRoom showed up and not CreateNewMessage
    – potatoonion
    Nov 21 '18 at 13:07












  • @potatoonion where did you see this createNewMessage method?
    – Rakesha Shastri
    Nov 21 '18 at 13:08










  • I read somewhere yesterday night that's how to create a message guess it was wrong, is there another way to create a message?
    – potatoonion
    Nov 21 '18 at 13:10










  • I'm not familiar with firebase. You should look up their documentation.
    – Rakesha Shastri
    Nov 21 '18 at 13:15










  • yea same, I'm kinda new to firebase too. I don't seem to still understand their documentation about creating new message tho :(
    – potatoonion
    Nov 21 '18 at 13:28


















1














The first error is because you are comparing UITextField object with a String. You should be comparing the text in the text field instead.



if chatTextfield.text != "" {
// do something
}


Or in a more Swifty way, like this,



if !chatTextfield.text!.isEmpty {
// do something
}


My knowledge in Firebase is next to none. So, i can't help you much with the second one. From the error, it is pretty clear that there is no method by that name. So, if you just got the method signature wrong, you should write DataService.dataService. and let firebase show you suggestions and pick the appropriate one.






share|improve this answer























  • thank you! the first problem got solved. I tried the DataService.dataService. but only createNewRoom showed up and not CreateNewMessage
    – potatoonion
    Nov 21 '18 at 13:07












  • @potatoonion where did you see this createNewMessage method?
    – Rakesha Shastri
    Nov 21 '18 at 13:08










  • I read somewhere yesterday night that's how to create a message guess it was wrong, is there another way to create a message?
    – potatoonion
    Nov 21 '18 at 13:10










  • I'm not familiar with firebase. You should look up their documentation.
    – Rakesha Shastri
    Nov 21 '18 at 13:15










  • yea same, I'm kinda new to firebase too. I don't seem to still understand their documentation about creating new message tho :(
    – potatoonion
    Nov 21 '18 at 13:28
















1












1








1






The first error is because you are comparing UITextField object with a String. You should be comparing the text in the text field instead.



if chatTextfield.text != "" {
// do something
}


Or in a more Swifty way, like this,



if !chatTextfield.text!.isEmpty {
// do something
}


My knowledge in Firebase is next to none. So, i can't help you much with the second one. From the error, it is pretty clear that there is no method by that name. So, if you just got the method signature wrong, you should write DataService.dataService. and let firebase show you suggestions and pick the appropriate one.






share|improve this answer














The first error is because you are comparing UITextField object with a String. You should be comparing the text in the text field instead.



if chatTextfield.text != "" {
// do something
}


Or in a more Swifty way, like this,



if !chatTextfield.text!.isEmpty {
// do something
}


My knowledge in Firebase is next to none. So, i can't help you much with the second one. From the error, it is pretty clear that there is no method by that name. So, if you just got the method signature wrong, you should write DataService.dataService. and let firebase show you suggestions and pick the appropriate one.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 22 '18 at 7:17

























answered Nov 21 '18 at 13:02









Rakesha Shastri

6,85921232




6,85921232












  • thank you! the first problem got solved. I tried the DataService.dataService. but only createNewRoom showed up and not CreateNewMessage
    – potatoonion
    Nov 21 '18 at 13:07












  • @potatoonion where did you see this createNewMessage method?
    – Rakesha Shastri
    Nov 21 '18 at 13:08










  • I read somewhere yesterday night that's how to create a message guess it was wrong, is there another way to create a message?
    – potatoonion
    Nov 21 '18 at 13:10










  • I'm not familiar with firebase. You should look up their documentation.
    – Rakesha Shastri
    Nov 21 '18 at 13:15










  • yea same, I'm kinda new to firebase too. I don't seem to still understand their documentation about creating new message tho :(
    – potatoonion
    Nov 21 '18 at 13:28




















  • thank you! the first problem got solved. I tried the DataService.dataService. but only createNewRoom showed up and not CreateNewMessage
    – potatoonion
    Nov 21 '18 at 13:07












  • @potatoonion where did you see this createNewMessage method?
    – Rakesha Shastri
    Nov 21 '18 at 13:08










  • I read somewhere yesterday night that's how to create a message guess it was wrong, is there another way to create a message?
    – potatoonion
    Nov 21 '18 at 13:10










  • I'm not familiar with firebase. You should look up their documentation.
    – Rakesha Shastri
    Nov 21 '18 at 13:15










  • yea same, I'm kinda new to firebase too. I don't seem to still understand their documentation about creating new message tho :(
    – potatoonion
    Nov 21 '18 at 13:28


















thank you! the first problem got solved. I tried the DataService.dataService. but only createNewRoom showed up and not CreateNewMessage
– potatoonion
Nov 21 '18 at 13:07






thank you! the first problem got solved. I tried the DataService.dataService. but only createNewRoom showed up and not CreateNewMessage
– potatoonion
Nov 21 '18 at 13:07














@potatoonion where did you see this createNewMessage method?
– Rakesha Shastri
Nov 21 '18 at 13:08




@potatoonion where did you see this createNewMessage method?
– Rakesha Shastri
Nov 21 '18 at 13:08












I read somewhere yesterday night that's how to create a message guess it was wrong, is there another way to create a message?
– potatoonion
Nov 21 '18 at 13:10




I read somewhere yesterday night that's how to create a message guess it was wrong, is there another way to create a message?
– potatoonion
Nov 21 '18 at 13:10












I'm not familiar with firebase. You should look up their documentation.
– Rakesha Shastri
Nov 21 '18 at 13:15




I'm not familiar with firebase. You should look up their documentation.
– Rakesha Shastri
Nov 21 '18 at 13:15












yea same, I'm kinda new to firebase too. I don't seem to still understand their documentation about creating new message tho :(
– potatoonion
Nov 21 '18 at 13:28






yea same, I'm kinda new to firebase too. I don't seem to still understand their documentation about creating new message tho :(
– potatoonion
Nov 21 '18 at 13:28




















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%2f53412466%2ferror-while-trying-to-build-a-send-button%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

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

TypeError: fit_transform() missing 1 required positional argument: 'X'