Skip to content

Instantly share code, notes, and snippets.

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