在Swift 4.0中使用CodingKeys枚举来忽略UIImage属性

Dou*_*oug 5 ios swift codable

我有以下结构.前3个属性从JSON解码,第4个属性用作缓存,如果图像被下载.

import UIKit

struct Thumbnail: Codable {
    let url: String
    let width: UInt
    let height: UInt

    var image: UIImage?

    enum CodingKeys: String, CodingKey {
        case url
        case width
        case height
    }
}
Run Code Online (Sandbox Code Playgroud)

当我尝试编译Xcode时告诉我Thumbnail不符合Decodable协议.我知道UIImage不符合Codable,但据我所知,使用CodingKeys枚举应该忽略image协议?任何建议将不胜感激:)