Strings only work when it's a literal?
alexisbronchart opened this issue · comments
Alexis Bronchart commented
Mattt commented
Your example constructs a dictionary with String
keys and AnyEncodable
values. Like the compiler error says, you can't put a String
value where an AnyEncodable
value is expected. The reason string literals work is that AnyEncodable
AnyEncodable
conforms to ExpressibleByStringLiteral
; in this context, string literals result in AnyEncodable
values, not String
.
You can convert a String
to AnyEncodable
using string interpolation (as you have in the next line of your example) or through an explicit initializer (AnyEncodable(bar)
).