Possible 4.1 Encodable regression? (+ segmentation fault)

The following code used to work fine in Swift 4.0:

let dict: [String: Encodable] = ["one": 1]
let encodable: Encodable = dict

With 4.1 this now results in the error:

Value of type '[String : Encodable]' does not conform to specified type 'Encodable'

In my search of a workaround, I tried

let encodable: Encodable = dict as! Encodable

but this results in a segmentation fault.

Can anyone recommend a workaround?

Encodable doesn't conform to Encodable and never did. The errors are just now more robust with the introduction of the conditional conformance added in 4.1.

Unfortunately you either need to specify the type or use a method of fuzzy matching like with AnyCodable or JSON.

You can read more about this on these threads:


I recommend you using such an enum. Depending on what you want to do with it, I think it isn‘t such a bad structure at all (depending on what you are going to do with it).

I agree, we actually moved from AnyCodable to something similar to JSON as it was just more predictable and manageable.