In this case, assigning Int to the typealias value typealias not equal to the assignment because it is overridden by your corresponding type:
// this declaration is equal since you HAVE TO provide the type for SomeType protocol SomeProtocol { typealias SomeType func someFunc(someVar: SomeType) }
This assignment provides a default type for SomeType , which is overridden by your implementation in SomeClass , but is especially useful for protocol extensions:
protocol Returnable { typealias T = Int // T is by default of type Int func returnValue(value: T) -> T } extension Returnable { func returnValue(value: T) -> T { return value } } struct AStruct: Returnable {} AStruct().returnValue(3) // default signature: Int -> Int
You get this feature for free only according to the protocol without specifying type T If you want to set your own type, write typealias T = String // or any other type in the body of the structure.
Some additional notes on the given code example
You solved the problem because you made it explicit, what type the parameter is. Swift also uses your used type:
class SomeClass: SomeProtocol { func someFunc(someVar: Double) { print(someVar) } }
So, SomeType protocol is defined as Double .
Another example where you can see that SomeType in the class declaration is not protocol related:
class SomeClass: SomeProtocol { typealias Some = Int func someFunc(someVar: Some) { print(someVar) } }
However, if you do something like this:
protocol SomeProtocol { typealias SomeType: SomeProtocol func someFunc(someVar: SomeType) }
SomeType must be of type SomeProtocol , which can be used for more explicit abstraction and more static code, whereas this:
protocol SomeProtocol { func someFunc(someVar: SomeProtocol) }
will be dynamically sent.