Why are public objc methods compiled private with -enable-library-evolution?

Given:

import Foundation
import Cocoa
@IBDesignable
public class NSImageX : NSImageView {
   public override func draw (_ dirtyRect: NSRect) {
        super.draw(dirtyRect)
        let path = NSBezierPath ()
        path.lineWidth = 8.0
        path.move(to: NSPoint (x:frame.minX, y:frame.minY))
        path.line(to: NSPoint(x:frame.maxX, y:frame.maxY))
        path.move(to: NSPoint (x:frame.maxX, y:frame.minY))
        path.line(to: NSPoint (x:frame.minX, y: frame.maxY))
        NSColor.red.set()
        path.stroke()
    }
}

With -enable-library-evolution turned on, the method draw is compiled as a private function:
0000000000002f70 t _$s13NSObjectTests8NSImageXC4drawyySo6CGRectVF and there is no dispatch thunk for it.
How is this supposed to be called now?

Method implementations are expected to have private linkage because there should be no reason to directly reference them from outside the module. External code ought to call the method by dispatching through the vtable or ObjC method table. If this is an override of an @objc method, the only public interface to dispatching it would be via objc_msgSend.

Thanks for the answer, @Joe_Groff. I can probably work around this.
FYI, I'm doing this to call these from C#, where my use case has always been: if I can call a swift method directly without odd marshaling, then call it, otherwise write a (swift) wrapper that can be called and call that instead, which is where this looks like it needs to go.

Generating a stub to have Swift do the call seems like a good idea for anything class- or protocol-related, so you don't have to reimplement all the various interactions that affect how these methods get invoked.

Terms of Service

Privacy Policy

Cookie Policy