Articles, podcasts and news about Swift development, by John Sundell.

Improved compiler errors for auto-synthesized conformances in Xcode 11

Published on 25 Jun 2019
Discover page 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.