Hi there, at very beginning I want to say sorry for my English as I am not native speaker :)
Today I found quite interesting behaviour which made me confused. I have defined 2 types + one extension in my code while implementing feature to app:
protocol TypeA {
func test()
}
class TypeB: TypeA {
func test() { }
}
extension Optional {
typealias WrappedType = Wrapped
}
TypeA and extension for Optional are defined in framework included to app project where TypeB is defined.
Then I wanted to do some type comparison to find correct object from array, thats when I found interesting behaviour. Here are 4 checks I made with their results:
- TypeB.self is TypeA.Type; result is true
- TypeB.self is Optional< TypeA >.WrappedType.Type; result is false
- Optional< TypeB >.WrappedType.self is Optional< TypeA >.WrappedType.Type; result is false
- Optional< TypeA >.WrappedType.self == TypeA.self; result is true
Now there is my question:
Why are checks from points 2 and 3 failing? From my understanding typealias WrappedType is just exposure of Optional's generic type Wrapped, which, I believe, should equal TypeA. It kind of bothers me because I am wondering if it is a bug where TypeA != TypeA or there is reason why check 1 and 2 aren't equal. Am I just not aware of some trait of swift?
I will be grateful for any response for that question and sorry if I made topic in wrong section :)