NativeScript / ios-jsc

NativeScript for iOS using JavaScriptCore
http://docs.nativescript.org/runtimes/ios
Apache License 2.0
299 stars 59 forks source link

swift method throwing having wrong typings, can't run #1071

Open farfromrefug opened 5 years ago

farfromrefug commented 5 years ago

I am trying to modify a swift library so that it can work with {N} https://github.com/Akylas/NextLevel

The idea was to add a few @objc ...

It almost all work flawlessly except for one method The start throws an error. I modified the Error type so that it is exposed too. But the typings resulting is wrong. I end up with this

    startAndReturnError(): void;

As you can see this is the correct method name but the error argument is missing. Can't find out why.

Anyone can help?

NathanaelA commented 5 years ago

Hi @farfromrefug,

You need to convert the Swift error type into a NSError. Many swift objects CANNOT go over the bridge into ObjC, if they can't bridge to ObjC they can't bridge to NativeScript. It is safest when dealing with Swift to use "Int", "NSString", "NSArray", "NSDictionary", etc and make sure your bridged types are of the standard ObjC types. Any swift structures, classes, enums are very very likely to not bridge into ObjC.

By the way when the meta data system can't figure out a compatible type it just removes it.