With the Swift umbrella header for the project added, Objective-C is able to access Swift class methods. How is Objective-C able to call Swift methods, but C not able to without working with name mangling issue?
Could you provide details on this?
Doesn't stable Swift ABI, mean, the compiler generates fixed mangled names for types? Then can we have a program to go through Swift source code and generate a header with the mangled names, which can be called from C?
Its compiler magic enabled by the @objc
attribute. When you mark a method, protocol, class or variable as @objc
the compiler will actually generate a thunk or stub function(s) with the appropriate objective C selector and name so that it can be called by the objective C run time and that thunk will then call the underlying Swift function. Note that Swift dispatch and Object message send are two entirely different things; its not just the method names, but also the way you look up the function pointers (v table for swift, string selectors for objc c) and pass the parameters. The compiler does a lot of work behind the scenes to make this happen, including bridging your parameters across the languages (NSString to String, etc).