Created
September 12, 2015 07:06
-
-
Save akio0911/e7db83e8bd23722f0cbe 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
protocol Base { | |
var name:String { get } | |
func doSomething() -> String | |
} | |
struct A : Base { | |
var name:String { return "Filter A" } | |
func doSomething() -> String { return "do A" } | |
} | |
struct B : Base { | |
var name:String { return "Filter B" } | |
func doSomething() -> String { return "do B" } | |
} | |
struct C : Base { | |
var name:String { return "Filter C" } | |
func doSomething() -> String { return "do C" } | |
} | |
let filters:[Base] = [ | |
A(), B(), C() | |
] | |
if let filter = filters.filter({ $0.name == "Filter A" }).first { | |
let result = filter.doSomething() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment