Created
May 4, 2015 19:33
-
-
Save Pretz/4d2d64c41f47ed22b54b 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
public func SelectTypedItemFromArray<T, U: SequenceType>(type t: T.Type, array: U) -> T? { | |
for eachItem in array { | |
if let typedItem = eachItem as? T { | |
return typedItem | |
} | |
} | |
return nil | |
} | |
let t: Double? = SelectTypedItemFromArray(type: Double.self, [1, 2, "lol", 5.2, "bar"] as [Any]) // == 5.2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment