简体   繁体   English

Swift alamofire错误

[英]Swift alamofire error

来自xcode的错误

So I'm trying to create a user on my database backend, everything is working on the app bar this segment on xcode, written in swift. 所以我正在尝试在我的数据库后端创建一个用户,一切都在应用程序栏上运行xcode上的这个段,用swift编写。

The backend can accept new users via this method but for some reason swift won't have it. 后端可以通过这种方法接受新用户,但由于某种原因,swift不会拥有它。

When I click register I get the error shown in the photo, code used 当我点击注册时,我得到照片中显示的错误,使用的代码

Alamofire.request(.POST, urlRequest, parameters: ["X-API-KEY": API_GENERAL_KEY,"username":userName.text!,"email": userMail.text!,"password":userPassword.text!,"profile_photo": self.imageName])

and the output is 而输出是

<spotimusic.RadioStyleCollectionViewController: 0x7fe313d8fd00> whose view is not in the window hierarchy!
SDSD -  Optional("nathan@trojan-audio.com")
fatal error: unexpectedly found nil while unwrapping an Optional value
(lldb) 

Another error which shows in a segment is 分段中显示的另一个错误是

来自xcode的错误2

Thanks for any help or suggestions 感谢您的任何帮助或建议

It seems that userName.text or userPassword.text doesn't have a value. 似乎userName.textuserPassword.text没有值。 This error can occur due to an unlinked outlet. 由于未连接的插座可能会发生此错误。

If your outlets are linked properly try this: 如果你的网点正确链接,试试这个:

guard let userName = userName.text, let userMail = userMail.text, let userPassword = userPassword.text else {
    return
} 
Alamofire.request(.POST, urlRequest, parameters: ["X-API-KEY": API_GENERAL_KEY,"username":userName,"email": userMai,"password":userPassword,"profile_photo": self.imageName])

You will be able to catch the empty values without crashes. 您将能够捕获空值而不会崩溃。

Let me know if it fixes your problem 如果它能解决您的问题,请告诉我

Thanks for all of the help guys, Marco's answer was the one that I used that fixed all the errors. 感谢所有帮助人员,Marco的回答是我使用的那个解决了所有错误的答案。

guard let userName = userName.text, let userMail = userMail.text, let userPassword = userPassword.text else {
return
} 
Alamofire.request(.POST, urlRequest, parameters: ["X-API-KEY": API_GENERAL_KEY,"username":userName,"email": userMai,"password":userPassword,"profile_photo": self.imageName])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM