I am using XCode 7.2
and Swift 2.2
. I have a function that accepts a dictionary([NSObject : AnyObject])
as a parameter. However, I want to call this function without using that dictionary or in other words by making the parameter nil. If I do that, this is thrown:
nil is not compatible with the expected argument type '[NSObject : AnyObject]'
My code is
self.silentPostData(
persist.getObject(
mdmiosagent_Constants.SERVERNAMEKEY) as String,
serverport: persist.getObject(mdmiosagent_Constants.SERVERPORTKEY) as String,
serverurl: mdmiosagent_Constants.NATIVE_APP_SERVLET,
parameters: nil ,
urldata: jsonData
)
)
The parameter in conflict is named parameters in the code. Thank you in advance.
Only nullable types (such as optionals or types that conform to the protocol NilLiteralConvertible
) can be nil
, or compared to nil
. Therefore, you have following options:
1. Make the parameter optional
convert the parameter of the function to [NSObject : AnyObject]?
2. Pass an empty dictionary
just call:
self.silentPostData(
persist.getObject(
mdmiosagent_Constants.SERVERNAMEKEY) as String,
serverport: persist.getObject(mdmiosagent_Constants.SERVERPORTKEY) as String,
serverurl: mdmiosagent_Constants.NATIVE_APP_SERVLET,
parameters: [:],
urldata: jsonData
)
)
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