1

Is there any way to extend a class in Objective C only for those subclasses that conform to a protocol, like that in Swift:

extension SomeClass where self: SomeProtocol {
// some code
}
CodeBrew
  • 6,457
  • 2
  • 43
  • 48

1 Answers1

1

There is no Objective-C syntax for that. (Not sure if there’s even a Swift syntax like this; we have a generic where clause, but not on self. And Objective-C doesn’t offer full generic implementation, only offering lightweight implementation.)

Rob
  • 415,655
  • 72
  • 787
  • 1,044
  • 2
    There is a `where self` (well, tather `where Self:`) https://stackoverflow.com/questions/46018677/what-is-where-self-in-protocol-extension – Larme Feb 22 '21 at 19:27
  • 1
    Yep, for Swift protocols, but not classes. And not in ObjC. – Rob Feb 22 '21 at 19:42