Last active
March 30, 2022 08:11
-
-
Save zeitiger/1387f7d996f64b493608 to your computer and use it in GitHub Desktop.
JSExportAs Workaround in Swift (simplified code example)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public typealias myFunctionDefAlias = (@objc_block (String, String, NSNumber) -> Void) | |
@objc | |
public protocol MyJSExportProtocol: JSExport { | |
// JSExportAs alternative in Swift via closure | |
var myFunction:myFunctionDefAlias? {get} | |
} | |
@objc | |
public class MyJSExportClass: NSObject, MyJSExportProtocol { | |
public var myFunction:myFunctionDefAlias? | |
public func init() { | |
self.myFunction = { [unowned self] (foo:String, bar:String, baz: NSNumber) in | |
self.myFunctionImpl(foo, bar: bar, baz: baz) | |
} | |
} | |
public func myFunctionImpl(foo: String, bar: String, baz: Bool) { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm getting the error:
@objc_block is an unknown attribute
Wish a workaround wasn't needed for JSExportAs.