Created
May 6, 2016 21:51
-
-
Save benjaminsnorris/289a079d64ade150f3224beb4894391a to your computer and use it in GitHub Desktop.
Unmarshaling Factory
This file contains 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
// From Bart Whiteley | |
public protocol UnmarshalingFactory: Marshal.ValueType { | |
associatedtype ConvertibleType = Self | |
static func createFromObject(object: MarshaledObject) throws -> ConvertibleType | |
} | |
extension UnmarshalingFactory { | |
public static func value(object: Any) throws -> ConvertibleType { | |
guard let convertedObject = object as? MarshaledObject else { | |
throw Error.TypeMismatch(expected: MarshaledObject.self, actual: object.dynamicType) | |
} | |
return try Self.createFromObject(convertedObject) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment