Associated types


Notes on associatedtype

protocol Thing {
    associatedtype argType
    func doit(val:argType) -> argType
}

class IntThing : Thing {
    func doit(val: Int) -> Int {
        return val + 1
    }
}

func doThing<A:Thing>(thing:A, val:A.argType) -> A.argType {
    return thing.doit(val)
}

doThing(IntThing(), 2)//3

See the mosby example for a more advance example: here

http://www.russbishop.net/swift-associated-types