Nathan Trojanaudio Bridge Nathan Trojanaudio Bridge - 1 month ago 5x
iOS Question

Swift alamofire error

Error from 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.

The backend can accept new users via this method but for some reason swift won't have it.

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("")
fatal error: unexpectedly found nil while unwrapping an Optional value

Another error which shows in a segment is

Error 2 from xcode

Thanks for any help or suggestions


It seems that userName.text or userPassword.text doesn't have a value. 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 {
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