Is there an easy way to determine what the symbols...
# ios
d
Is there an easy way to determine what the symbols that are exported to objective C are when creating a kotlin mp framework for consumption by iOS? It looks like the swift exports are obvious / can be read in the shared.h file, but I can't determine what the objective C symbols are
s
The header file in your framework contains all of the objective-c exports. There are
___attribute___
entries to give it a friendly Swift name.
Copy code
__attribute__((swift_name("MyClass")))
@interface MyCo_myModuleMyClass : NSObject
- (instancetype)initWithChar:(char)value; 
+ (instancetype)myClassWithChar:(char)value;
@end;
Here’s a heavily redacted example.
@interface
declares the class. In this case it inherits from NSObject. Methods that start with a
-
are instance methods and methods with a
+
are static methods. In swift you would declare a variable of this type using:
Copy code
let foo: MyClass = MyClass(char: "x")
My ObjC is a bit rusty so this syntax may be slightly off but it should be something like:
Copy code
MyCo_myModuleMyClass foo = [[MyCo_myModuleMyClass alloc] initWithChar: "x"];
d
thank you - i realiezed the docs gave a pretty good summary - the tooling i was using to import was breaking
s
Xcode tries to be helpful but in strange ways. If you command click on a Kotlin/Native class to navigate to the symbol while in a swift file, it’ll open up a Swift view of the header file. I suppose they’re just trying to hide the “ugly” objC when they can.
d
I was mainly asking because I'm trying to use it in another utility (appcelerator) and appcelerator isn't bridging the headers annotated with @protocol 😞 https://stackoverflow.com/questions/63834801/hyperloop-not-generating-javascript-binding-for-protocol-header
s
Javascript doesn’t have the notion of a class interface/protocol. It will call
foo.bar()
if the bar method exists on the foo object or just error out. You could always provide a factory function like
createAFooObject()
or object to the javascript vm. You are going to run into some difficult issues when exposing a K/N object into a javascript vm. Any Kotlin object to add to the vm or create in JS code will need to be frozen or the js garbage collector is going to crash your app.