Last active
February 1, 2018 21:37
-
-
Save tmspzz/53f43a767e96eb16ff7176f2e8000af1 to your computer and use it in GitHub Desktop.
Decodable Conformance of Enum backed with RawType Struct conforming to ExpressibleByStringLiteral
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
public struct Bar: Codable { | |
let value: String | |
public init(bar: Bar) { | |
self.value = bar.value | |
} | |
} | |
extension Bar: ExpressibleByStringLiteral { | |
public typealias StringLiteralType = String | |
public init(unicodeScalarLiteral value: UnicodeScalar) { | |
self.value = "\(value)" | |
} | |
public init(extendedGraphemeClusterLiteral value: String) { | |
self.value = value | |
} | |
public init(stringLiteral value: String) { | |
self.value = value | |
} | |
} | |
enum Foo: Bar, Codable { // Change RawType to String, everything is fine | |
case foo = "Foo" | |
} | |
struct Baz: Codable { | |
let f: Foo | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment