Lets say I have created this protocol and a couple of classes
import UIKit
protocol ControllerConstructorProtocol {
class func construct() -> UIViewC
Try this:
var myConst = MyConstructor()
var myOthConst = MyOtherConstructor()
var array:[AnyObject] = [
myConst,
myOthConst
]
for a in array
{
if a is MyConstructor
{
println("a is type of MyConstructor")
(a as! MyConstructor).myMethod()
}
else if a is MyOtherConstructor
{
println("a is type of MyOtherConstructor")
(a as! MyOtherConstructor).myMethod()
}
}
Another solution, although not that pretty...