Skip to content

Instantly share code, notes, and snippets.

@akio0911
Created September 12, 2015 07:06
Show Gist options
  • Save akio0911/e7db83e8bd23722f0cbe to your computer and use it in GitHub Desktop.
Save akio0911/e7db83e8bd23722f0cbe to your computer and use it in GitHub Desktop.
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