Skip to content

Commit

Permalink
Add handling for Int8-Int64 in Any+Codable extension
Browse files Browse the repository at this point in the history
  • Loading branch information
iabudiab committed Apr 24, 2021
1 parent aa876f0 commit 3ccc5dc
Showing 1 changed file with 50 additions and 6 deletions.
56 changes: 50 additions & 6 deletions Sources/Codable/Any+Codable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,12 @@ extension KeyedDecodingContainer {
for key in allKeys {
if let value = try? decode(Bool.self, forKey: key) {
dictionary[key.stringValue] = value
} else if let value = try? decode(Double.self, forKey: key) {
dictionary[key.stringValue] = value
} else if let value = try? decode(Int.self, forKey: key) {
dictionary[key.stringValue] = value
} else if let value = try? decode(UInt.self, forKey: key) {
dictionary[key.stringValue] = value
} else if let value = try? decode(Double.self, forKey: key) {
dictionary[key.stringValue] = value
} else if let value = try? decode(String.self, forKey: key) {
dictionary[key.stringValue] = value
} else if let value = try? decode([String: Any].self, forKey: key) {
Expand Down Expand Up @@ -128,10 +130,12 @@ extension UnkeyedDecodingContainer {
while isAtEnd == false {
if let value = try? decode(Bool.self) {
array.append(value)
} else if let value = try? decode(Double.self) {
array.append(value)
} else if let value = try? decode(Int.self) {
array.append(value)
} else if let value = try? decode(UInt.self) {
array.append(value)
} else if let value = try? decode(Double.self) {
array.append(value)
} else if let value = try? decode(String.self) {
array.append(value)
} else if let value = try? decode([String: Any].self) {
Expand Down Expand Up @@ -160,10 +164,30 @@ extension KeyedEncodingContainerProtocol where Key == JSONCodingKeys {
switch value {
case let value as Bool:
try encode(value, forKey: key)
case let value as Double:
try encode(value, forKey: key)
case let value as Int:
try encode(value, forKey: key)
case let value as Int8:
try encode(value, forKey: key)
case let value as Int16:
try encode(value, forKey: key)
case let value as Int32:
try encode(value, forKey: key)
case let value as Int64:
try encode(value, forKey: key)
case let value as UInt:
try encode(value, forKey: key)
case let value as UInt8:
try encode(value, forKey: key)
case let value as UInt16:
try encode(value, forKey: key)
case let value as UInt32:
try encode(value, forKey: key)
case let value as UInt64:
try encode(value, forKey: key)
case let value as Float:
try encode(value, forKey: key)
case let value as Double:
try encode(value, forKey: key)
case let value as String:
try encode(value, forKey: key)
case let value as [String: Any]:
Expand Down Expand Up @@ -212,10 +236,30 @@ extension UnkeyedEncodingContainer {
switch value {
case let value as Bool:
try encode(value)
case let value as Float:
try encode(value)
case let value as Double:
try encode(value)
case let value as Int:
try encode(value)
case let value as Int8:
try encode(value)
case let value as Int16:
try encode(value)
case let value as Int32:
try encode(value)
case let value as Int64:
try encode(value)
case let value as UInt:
try encode(value)
case let value as UInt8:
try encode(value)
case let value as UInt16:
try encode(value)
case let value as UInt32:
try encode(value)
case let value as UInt64:
try encode(value)
case let value as String:
try encode(value)
case let value as [String: Any]:
Expand Down

0 comments on commit 3ccc5dc

Please sign in to comment.