I've encountered following error while uploading Swift3 using XCode8.
'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 that issue. I've already tried with let param: NSDictionary
but got same error message.
First of all in Swift 3 the Objective-C equivalent of id
is Any
rather than AnyObject
, that avoids also the AnyObject
castings.
The error message indicates that an illegal type is used (Parameters
), JSON supports only string
, number
, <null>
and array
/ dictionary
.
In your case the dictionary is [String:String]
, a type annotation is not needed at all
let param = [
"email" : txrNRC.text,
"password" : txtPassword.text
]
If txrNRC
and txtPassword
are optionals you need to unwrap them or use the nil coalescing operator to assign a placeholder if the value is nil
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With