Weekly Swift articles, podcasts and tips by John Sundell.

Improved compiler errors for auto-synthesized conformances in Xcode 11

Published on 25 Jun 2019
Basics article available: Codable

New in Xcode 11/Swift 5.1: The compiler will now tell you why it can't auto-synthesize conformance to protocols like Encodable and Decodable, instead of just suggesting a manual implementation. Let’s say we have the following type, that we wish to conform to Decodable automatically:

struct ItemMetadata: Decodable {
    var date: Date
    var format: ItemFormat
    var category: String
}

If the ItemFormat type used above isn’t Decodable, then the compiler will now give us the following error:

Cannot automatically synthesize 'Decodable' because 'ItemFormat'
does not conform to Decodable.