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

1

7

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?

Patrinapatriot answered 25/6, 2015 at 12:19 Comment(2)
You should file this as a bug, bridging should be implicit. For the time being, try using NSMutableDictionary as a replacement.Gendarmerie
Thanks for the suggestion, but using NSMutableDictionary instead makes no differencePatrinapatriot
J
0

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.

Jaclin answered 28/11, 2016 at 3:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.