Created
May 4, 2015 19:21
-
-
Save erica/19be5f458a40b909f9df 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
/// Fetch item by class | |
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 | |
} | |
// Filter array by class | |
public func FilterTypeFromArray<T, U>(type t: T.Type, array: Array<U>) -> [T] { | |
return array.flatMap{ | |
if let item = $0 as? T { | |
return [item] | |
} else { return [] } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment