ios - Pass NSDictionary from Javascript to Objective-c in JavascriptCore -


i'm using javascriptcore in app. now, i'm passing variables jscontext can passed objective-c. however, 1 of variables, nsdictionary, not passing through correctly. run code below:

var evaluate = function(variables) {     app.setdictionary(variables.dictionary); } 

this simple example has these following methods set in jscontext.

this setdictionary() method:

- (void)setdicationary:(nsdictionary *)dictionary {     self.mutabledictionary = [dictionary mutablecopy]; } 

this variables.dictionary:

- (nsdictionary *)dictionary {     return self.values; } 

and how call evaluate():

jsvalue *jsfunction = self.context[@"evaluate"]; jsvalue *value = [jsfunction callwitharguments:@[self.variables]]; 

however, in setdictionary method, don't nsdictionary, instead nsstring containing [object object].

any ideas how can solve this?

although javascriptcore automatically converts types between objective-c or swift , javascript, suggest implement explicit conversion. automatic conversion doesn't work developer may expect. example undefined converted @"undefined" in case, when nsstring used.

try like:

- (void)setdicationary:(jsvalue *)jsdictionary {     if ([jsdictionary isundefined] || [jsdictionary isnull]) {         jsdictionary = nil;     }     self.mutabledictionary = [jsdictionary todictionary]; } 

note javascript uses object dictionary, should careful argument passing objective-c code. passing system object result recursive conversion of object nsdictionary.


Comments

Post a Comment

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -