Search code examples
ios7javascriptcore

iOS JavascriptCore: pass primitive boolean to js callback?


Say I have a method that can be called from JS:

- (void)doStuffToArray:(NSArray *)array withCompletion:(JSValue *)completion
{
    // do things to array
    [completion callWithArguments:@[...]];
}

And in JS it would be called like so:

doStuffToArrayWithCompletion(array, function (success) {
    if (success) ....
});

How do I pass in a primitive boolean value via callWithArguments?


Solution

  • You need to wrap any primitive values in a NSNumber:

    [completion callWithArguments:@[@(YES)]];