Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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