Last active
August 28, 2017 21:14
-
-
Save vhart/d2a1ec10028e086459e888b8f44632b5 to your computer and use it in GitHub Desktop.
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
class BaseJsonDeserializer<T>: JsonDeserializer { | |
init() { | |
guard type(of: self) != BaseJsonDeserializer.self | |
else { fatalError("do not initialize this abstract class directly") } | |
} | |
func parse(json: [String : Any]) -> T { | |
fatalError("Abstract class. Subclass must override") | |
} | |
} | |
class DeserializerBox<D: JsonDeserializer>: BaseJsonDeserializer<D.Response> { | |
private let deserializer: D | |
init(concreteDeserializer: D) { | |
self.deserializer = concreteDeserializer | |
} | |
override func parse(json: [String : Any]) -> D.Response { | |
return deserializer.parse(json: json) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment