Reputation: 15039
I have the following code that was working great in swift 2.3
"code": self.searchByCode == true ? description : NSNull(),
In Swift 3 Im getting this error.
Any clue?
Upvotes: 0
Views: 39
Reputation: 8396
I suggest using nil
instead of NSNull()
especially you are using the Swift 3 as the following:
self.searchByCode == true ? description : nil
And it should make the error goes away.
Upvotes: 1
Reputation: 19892
Your problem is that this expression self.searchByCode == true ? description : NSNull()
can result in either a String
or NSNull
, so the compiler can't infer it's type.
You can store it in a Any
variable before adding it to the dict or you could try this (I think this could work but I haven't tried it):
(self.searchByCode == true ? description : NSNull()) as Any
Upvotes: 0