Flight-School / AnyCodable

Type-erased wrappers for Encodable, Decodable, and Codable values
https://flight.school/books/codable
MIT License
1.28k stars 132 forks source link

Cannot convert value of type 'String' to expected argument type 'AnyCodable' #35

Closed bakshioye closed 4 years ago

bakshioye commented 4 years ago

I am trying to assign a String value to a property that has a type AnyCodable but cannot assign it. Any way I can assign the value to the property?

Screenshot 2020-06-10 at 5 50 28 PM

bakshioye commented 4 years ago

Okay got it. In case anyone needs the answer in future, I'll just put it here

For assigning a value, use one of the initialisers

finalSearchField.inputValue = AnyCodable(stringLiteral: )

and if you want to fetch the value that is for a property that is declared AnyCodable, use .value for that property, like :

finalSearchField.inputValue?.value

and then cast it to any value you want like to String usingas? String