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
.
How to save figure in matplotlib pyplot
ReplyDeletePython Matplotlib 3D Plot
NextworkX Python Overview
How to display doc file in PHP from database
How to convert text to speech using PHP
How to create a multiple choice quiz in PHP and MySQL