If I have the following code:
protocol ObjectType { var title: String { get set } } extension ObjectType { var objectTypeString: String { let mirror = Mirror(reflecting: self) return "\(mirror.subjectType)" } } class Object: ObjectType { var title = "" } class SomeOtherClass { private func someFunc<T: Object>(object: T) { print(object.objectTypeString) } }
where Object corresponds to ObjectType , you can expect that you will be able to access objectTypeString on any ObjectInstance . But the compiler says that Type T has no member objectTypeString when this member is accessed by some common type that inherits from Object , as shown in the code above. When a function is not generic and simply passes into the Object parameter, there is no problem. So, why should the parameter be shared, so I canβt access the protocol member that the corresponding class should have access to?
I came across this question here , but I'm not interested in workarounds, I just would like to understand that this applies to the general system, which makes my example not work. (A simple workaround is <T: ObjectType> )
source share