NullCodable

@propertyWrapper
public struct NullCodable<T>
extension NullCodable: Encodable where T: Encodable
extension NullCodable: Decodable where T: Decodable

Заставляет Encodable and Decodable свойства превращаться в null вместо того, чтобы убирать значения из объекта при сериализации.

struct User: Codable {
    var name: String = ""
    @NullCodable var favMusicAlbum: String?
}
// При декодировании структуры или в использовании Alamofire
// Получается такой json
// Output json:
// { "name": "",  favMusicAlbum: null }
  • Значение, которое может оказаться null(nil)

    Declaration

    Swift

    public var wrappedValue: T?
  •  Init

    Declaration

    Swift

    public init(wrappedValue: T?)

    Parameters

    wrappedValue

    Значение, которое может оказаться null(nil)

Available where T: Encodable

  • Declaration

    Swift

    public func encode(to encoder: Encoder) throws

Available where T: Decodable

  • Declaration

    Swift

    public init(from decoder: Decoder) throws