This seems similar to Override on class funcs, but since it’s not a static override, I thought I’d submit it separately:
override func isEqual(_ object: Any?) -> Bool { // Error: no method to override
...
}
This seems similar to Override on class funcs, but since it’s not a static override, I thought I’d submit it separately:
override func isEqual(_ object: Any?) -> Bool { // Error: no method to override
...
}
What’s the base class? iirc NSObject itself does not implement isEqual, only INSObject, the interface, defines it.
The following works fine in XCode:
class Foo: NSObject {
override func isEqual(_ object: Any?) -> Bool {
return true}
}
I’m not sure where NSObject is picking up it’s implementation of isEqual from, but it’s definitely in the NSObjectProtocol which it exports. Here’s what XCode shows me when I command-click on NSObject:
import ObjectiveC
public protocol NSObjectProtocol {
public func isEqual(_ object: Any?) -> Bool
public var hash: Int { get }
public var superclass: Swift.AnyClass? { get }
public func `self`() -> Self
public func perform(_ aSelector: Selector!) -> Unmanaged<AnyObject>!
public func perform(_ aSelector: Selector!, with object: Any!) -> Unmanaged<AnyObject>!
public func perform(_ aSelector: Selector!, with object1: Any!, with object2: Any!) -> Unmanaged<AnyObject>!
public func isProxy() -> Bool
public func isKind(of aClass: Swift.AnyClass) -> Bool
public func isMember(of aClass: Swift.AnyClass) -> Bool
@available(iOS 2.0, *)
public func conforms(to aProtocol: Protocol) -> Bool
public func responds(to aSelector: Selector!) -> Bool
public var description: String { get }
optional public var debugDescription: String { get }
}
@available(iOS 2.0, *)
open class NSObject : NSObjectProtocol {
open class func load()
open class func initialize()
public init()
@available(*, deprecated, message: "Objective-C garbage collection is no longer supported")
open func finalize()
open func copy() -> Any
open func mutableCopy() -> Any
open class func instancesRespond(to aSelector: Selector!) -> Bool
open class func conforms(to protocol: Protocol) -> Bool
open func method(for aSelector: Selector!) -> IMP!
open class func instanceMethod(for aSelector: Selector!) -> IMP!
open func doesNotRecognizeSelector(_ aSelector: Selector!)
@available(iOS 2.0, *)
open func forwardingTarget(for aSelector: Selector!) -> Any?
open class func isSubclass(of aClass: Swift.AnyClass) -> Bool
@available(iOS 2.0, *)
open class func resolveClassMethod(_ sel: Selector!) -> Bool
@available(iOS 2.0, *)
open class func resolveInstanceMethod(_ sel: Selector!) -> Bool
open class func hash() -> Int
open class func superclass() -> Swift.AnyClass?
open class func description() -> String
open class func debugDescription() -> String
}
extension NSObject : Equatable, Hashable {
/// The hash value.
///
/// **Axiom:** `x == y` implies `x.hashValue == y.hashValue`
///
/// - Note: the hash value is not guaranteed to be stable across
/// different invocations of the same program. Do not persist the
/// hash value across program runs.
open var hashValue: Int { get }
}
extension NSObject : CVarArg {
}
IIRC there’s an open issue form Silver to allow override
on methods that come from interfaces and are not implemented in the base class (ie Java style). Swift supports that, but we currently don’t, we only support/allow override when you are actually overriding a base class method, right now.
Thanks for taking the time to look into this.
How are you concluding that NSObject does not implement isEqual? The following compiles and runs fine in XCode and at least compiles in Silver:
func test() -> Bool {
let x = NSObject()
return x.isEqual(x)
}
Also, I thought Swift required all non-optional functions in a protocol to be implemented by any implementing class. Do you think the listing that XCode provided for NSObjectProtocol is just wrong in not representing isEqual as optional?