Why can't I set a Swift dictionary item exposed to JavaScriptCore?

258 views Asked by At

I have a Swift object that I'm exposing to JavaScriptCore like this:

@objc(MyObjectExport) protocol MyObjectExport:JSExport {
    var name:String {get set}
    var dict:[String:String] {get set} }

class MyObject:NSObject,MyObjectExport {
    var name:String="Name"
    var dict:[String:String]=["test":"TEST"] }

In the Javascript context I can happily get and set the 'name' property of a MyObject instance, but can only get, not set, the 'dict' dictionary items.

What am I missing, or is this a bug?

1

There are 1 answers

0
Steven On

ECMAScript 5 doesn't support custom scripting. By exposing Dictionary to JavaScriptCore, you will be able to do something in JavaScriptCore like

MyObjectExport['key'] = value;

But it won't work in JavaScriptCore at this stage.