dazza5000
09/09/2020, 5:39 PMSam
09/09/2020, 7:24 PM___attribute___
entries to give it a friendly Swift name.
__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:
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:
MyCo_myModuleMyClass foo = [[MyCo_myModuleMyClass alloc] initWithChar: "x"];
dazza5000
09/09/2020, 7:29 PMdazza5000
09/09/2020, 7:29 PMSam
09/10/2020, 4:57 PMdazza5000
09/10/2020, 6:19 PMSam
09/10/2020, 9:53 PMfoo.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.