Skip to content

Instantly share code, notes, and snippets.

@Pretz
Created May 4, 2015 19:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pretz/4d2d64c41f47ed22b54b to your computer and use it in GitHub Desktop.
Save Pretz/4d2d64c41f47ed22b54b to your computer and use it in GitHub Desktop.
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