-
Hello, I was reading those two tutorials and experimenting a little bit with them: Throughout that journey I was however having some issues trying to connect the knowledge from those two guides together. Could you please advise on what kind of glue code do I need to write in order to be able to emit events from the Swift portion of the code? I'm not too experienced with Objective-C and thus I'm not sure how to approach on exposing I would be very grateful if somebody could provide an advice here. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
To expose ObjC stuff to Swift you need a "bridging header". If you do "New swift file" in your project in Xcode it should prompt you to set one up automatically. If it doesn't, this page has manual instructions: https://developer.apple.com/documentation/swift/importing-objective-c-into-swift If you have one automatically imported its default contents will be: //
// Use this file to import your target's public headers that you would like to expose to Swift.
//
And then, as it says, you #import .h files into here if you want to expose them to Swift. |
Beta Was this translation helpful? Give feedback.
-
I've figured that one out. Just for the record, it was something like that. On the Objective-C side: - (id) init {
if (self = [super init]) {
storage = [NativeLocalStorage new];
[storage setEmitOnKeyAdded:^(NSString *key, NSString *value){
[self emitOnKeyAdded:@{@"key": key, @"value": value}];
}];
}
return self;
} On the Swift side:
And then the autogenerated emit method can be accessed from the Swift code. |
Beta Was this translation helpful? Give feedback.
I've figured that one out. Just for the record, it was something like that.
On the Objective-C side:
On the Swift side:
And then the autogenerated emit method can be accessed from the Swift code.