Created
October 19, 2015 12:30
-
-
Save mhuusko5/2191f4054f22682f0af1 to your computer and use it in GitHub Desktop.
Swift – func ensureType<T>(type type: T.Type = T.self, transform: (Any) -> T)(_ any: Any) -> T
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
func ensureType<T>(type type: T.Type = T.self, transform: (Any) -> T)(_ any: Any) -> T { | |
return ensureType(any, type: type, transform: transform) | |
} | |
func ensureType<T>(any: Any, type: T.Type = T.self, transform: (Any) -> T) -> T { | |
if let any = any as? T { | |
return any | |
} else { | |
return transform(any) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment