Created
May 4, 2015 19:07
-
-
Save Pretz/11665238740bb8082ed5 to your computer and use it in GitHub Desktop.
This file contains 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
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