unexpectedly found nil while unwrapping an Optional value - Using ALAMOFIRE

Jason

I am trying to use Alamofire for GETs in JSON. When I use one URL - It works fine and when I use another I get an error unwrapping an optional value. I cannot seem to track where the error is coming from. I have resorted in putting the code in ViewDidLoad to track the error. I don't know if its the recipient and they want some sort of authorisation. but I know its not the println's cos when i // them - it still comes up as an error , heres the code :

request(.GET, "https://api.doingdata.net/sms/send?api_service_key='APIKey'&msg_senderid=Edify-FYI&msg_to=&msg_text={otp|Edify-FYI|3600|ETEN|4} &msg_clientref=abcdef123456&msg_dr=0&output=json")
        .validate()
        .responseJSON { (_, _, _, error) in
            println(error)
    }

but I use :

request(.GET, "http://httpbin.org/")
            .validate()
            .responseJSON { (_, _, _, error) in
                println(error)
        }

it works fine and returns nil for the error.

Any help would be great, as its driving me nuts.

avismara

The reason is simple: your URL has special characters. So, if you do

let url = NSURL(string:yourURLString) //returns nil

It will return nil. You would need to format your URL to be suitable for making requests. Here is one solution for you.

var urlString = "https://api.doingdata.net/sms/send?api_service_key='APIKey'&msg_senderid=Edify-FYI&msg_to=&msg_text={otp|Edify-FYI|3600|ETEN|4} &msg_clientref=abcdef123456&msg_dr=0&output=json"
urlString = urlString.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet())!
request(.GET, urlString, parameters: nil, encoding: .JSON)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Unexpectedly found nil while unwrapping optional value

From Dev

Unexpectedly found nil while unwrapping an - Optional Value

From Dev

Alamofire URL Request - unexpectedly found nil when unwrapping an Optional Value

From Dev

Swift Alamofire - fatal error: unexpectedly found nil while unwrapping an Optional value - youtube api: PlaylistItems: list

From Dev

unexpectedly found nil while unwrapping an Optional value(optional binding)

From Dev

Unexpectedly found nil while unwrapping an Optional value while opening UIViewController

From Dev

Getting nil values using NSDate (fatal error: unexpectedly found nil while unwrapping an Optional value)

From Dev

unexpectedly found nil while unwrapping an Optional value : swift 2.1

From Dev

fatal error: unexpectedly found nil while unwrapping an Optional value swift

From Dev

Dictionary Unexpectedly found nil while unwrapping an Optional value

From Dev

Swift: UIImageView - Unexpectedly found nil while unwrapping an Optional value

From Dev

Fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)

From Dev

fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)

From Dev

.reloadData() fatal error: unexpectedly found nil while unwrapping an Optional value

From Dev

Header Custom View: unexpectedly found nil while unwrapping an Optional value

From Dev

Unexpectedly found nil while unwrapping an Optional value swift

From Dev

UILabel - unexpectedly found nil while unwrapping an Optional value

From Dev

Swift - Error: unexpectedly found nil while unwrapping an optional value

From Dev

fatal error: unexpectedly found nil while unwrapping an Optional value

From Dev

swift fatal error: unexpectedly found nil while unwrapping an Optional value

From Dev

reloadData() fatal error: unexpectedly found nil while unwrapping an Optional value

From Dev

Getting unexpectedly found nil while unwrapping an Optional value

From Dev

unexpectedly found nil while unwrapping an Optional value - Sprite Kit

From Dev

Adding Anotation causes unexpectedly found nil while unwrapping an Optional value

From Dev

Unexpectedly found nil while unwrapping an Optional value - Plist

From Dev

Unexpectedly found nil while unwrapping an Optional value (UIButton)

From Dev

catching all "unexpectedly found nil while unwrapping an Optional value"

From Dev

iOS - Unexpectedly found nil while unwrapping optional value

From Dev

Swift error: unexpectedly found nil while unwrapping an Optional value

Related Related

  1. 1

    Unexpectedly found nil while unwrapping optional value

  2. 2

    Unexpectedly found nil while unwrapping an - Optional Value

  3. 3

    Alamofire URL Request - unexpectedly found nil when unwrapping an Optional Value

  4. 4

    Swift Alamofire - fatal error: unexpectedly found nil while unwrapping an Optional value - youtube api: PlaylistItems: list

  5. 5

    unexpectedly found nil while unwrapping an Optional value(optional binding)

  6. 6

    Unexpectedly found nil while unwrapping an Optional value while opening UIViewController

  7. 7

    Getting nil values using NSDate (fatal error: unexpectedly found nil while unwrapping an Optional value)

  8. 8

    unexpectedly found nil while unwrapping an Optional value : swift 2.1

  9. 9

    fatal error: unexpectedly found nil while unwrapping an Optional value swift

  10. 10

    Dictionary Unexpectedly found nil while unwrapping an Optional value

  11. 11

    Swift: UIImageView - Unexpectedly found nil while unwrapping an Optional value

  12. 12

    Fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)

  13. 13

    fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)

  14. 14

    .reloadData() fatal error: unexpectedly found nil while unwrapping an Optional value

  15. 15

    Header Custom View: unexpectedly found nil while unwrapping an Optional value

  16. 16

    Unexpectedly found nil while unwrapping an Optional value swift

  17. 17

    UILabel - unexpectedly found nil while unwrapping an Optional value

  18. 18

    Swift - Error: unexpectedly found nil while unwrapping an optional value

  19. 19

    fatal error: unexpectedly found nil while unwrapping an Optional value

  20. 20

    swift fatal error: unexpectedly found nil while unwrapping an Optional value

  21. 21

    reloadData() fatal error: unexpectedly found nil while unwrapping an Optional value

  22. 22

    Getting unexpectedly found nil while unwrapping an Optional value

  23. 23

    unexpectedly found nil while unwrapping an Optional value - Sprite Kit

  24. 24

    Adding Anotation causes unexpectedly found nil while unwrapping an Optional value

  25. 25

    Unexpectedly found nil while unwrapping an Optional value - Plist

  26. 26

    Unexpectedly found nil while unwrapping an Optional value (UIButton)

  27. 27

    catching all "unexpectedly found nil while unwrapping an Optional value"

  28. 28

    iOS - Unexpectedly found nil while unwrapping optional value

  29. 29

    Swift error: unexpectedly found nil while unwrapping an Optional value

HotTag

Archive