1

I'm using a class, which is originally written in Swift, that extends NSObject from a third-party XCFramework:

open class ExampleClass: NSObject, Codable { ... }

Since this is a third-party class, I can't modify the original, so I created an extension on top of it to override isEqual(_ object:):

extension ExampleClass {
    override open func isEqual(_ object: Any?) -> Bool {
        return true
    }
}

This is currently compiling and building fine on Xcode 11, but with the same branch on Xcode 12, I'm getting an error that says '@objc' instance method in extension of subclass of 'ExampleClass' requires iOS 13.0.0

I've found a similar issue that seems to imply that functionality can't be overridden in a Swift extension, but I'm trying to understand what's changed since migrating from Xcode 11 to 12. Was there something that changed recently that prevents this from happening? Any thoughts on working around this?

Jeriel Ng
  • 191
  • 1
  • 4
  • 14
  • 4
    Overriding methods in extensions was banned a while ago in Swift, not sure why it worked for you in Xcode 11. Maybe because the class was Objective-C, and part of a different framework, still the Swift compiler shouldn't have let you do this. – Cristik Nov 19 '20 at 17:52
  • 1
    Very useful details about overriding in extensions here: https://stackoverflow.com/questions/38213286/overriding-methods-in-swift-extensions – Cristik Nov 21 '20 at 10:37
  • Thanks for the reference! Yep, it definitely appears we can’t override methods in extensions, which surprises me how it was able to compile before on a previous version of Xcode. I ended up working around it by defining the function as its own thing rather than overriding it, although it’s not ideal. – Jeriel Ng Nov 22 '20 at 00:18

0 Answers0