(: "Parser" ), , , . : ();
(A, B, C...) .
Parsing ( , ), Parser.
forEach Parser.parse();... , , .
(A, B, C...) ( ). ParsingController ( ), , . , ( ).
UPDATE: , , .
UPDATE2: , , - / /.
import Swift
protocol Parser {
func parse(code1: Int, code2: Int) -> Bool
}
extension Parser {
var someCalculatedProperty: Int {
return 12345
}
func someCommonMethod() {
print("Some Common Method")
}
}
class A : Parser {
func parse(code1: Int, code2: Int) -> Bool { return false }
}
class B : Parser {
func parse(code1: Int, code2: Int) -> Bool { return false }
}
class C : Parser {
func parse(code1: Int, code2: Int) -> Bool { return true }
}
var parsers = [Parser](arrayLiteral: A(), A(), B(), C())
for parser in parsers {
if parser.parse(0, code2: 1) {
print("Success")
parser.someCommonMethod()
print(parser.someCalculatedProperty)
break
} else {
print("Fail")
}
}
:
Fail
Fail
Fail
Success
Some Common Method
12345
3 ( A, A, B false) Success - C, true. .