Skip to content

Instantly share code, notes, and snippets.

@Pretz
Created May 4, 2015 19:07
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/11665238740bb8082ed5 to your computer and use it in GitHub Desktop.
Save Pretz/11665238740bb8082ed5 to your computer and use it in GitHub Desktop.
import Foundation
public func SelectTypedItemFromArray<T>(array: [AnyObject]) -> T? {
for eachItem in array {
if let typedItem = eachItem as? T {
return typedItem
}
}
return nil
}
let t: String? = SelectTypedItemFromArray([1, 2, "lol"])
println(t) // Optional("lol")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment