"NSInvalidArgumentException", reason: "Invalid JSON record type (_SwiftValue)" with alamofire swift3

When booting Swift3 using Xcode8, I ran into the following error.

'NSInvalidArgumentException', reason: 'Invalid type in JSON write (_SwiftValue)'

let param: Parameters = [ "email":txrNRC.text as AnyObject, "password":txtPassword.text as AnyObject ] 

Please let me know how to solve this problem. I already tried with let param: NSDictionary , but got the same error message.

+6
source share
1 answer

First of all, in Swift 3, the equivalent of Objective-C id is Any , not AnyObject , which also avoids casting AnyObject .

The error message indicates that an illegal type ( Parameters ) is being used, JSON only supports string , number , <null> and array / dictionary .

In your case, the dictionary [String:String] , type annotation is not required at all

 let param = [ "email" : txrNRC.text, "password" : txtPassword.text ] 

If txrNRC and txtPassword are optional, you need to expand them or use the nil join operator to assign a placeholder if nil

+8
source

Source: https://habr.com/ru/post/1011854/


All Articles