NativeScript Core

Not finding the help you need?

Function Pointers

To create a native function pointer from a JavaScript function you must use the interop.FunctionReference() constructor which accepts a single parameter - a JavaScript function. You must keep the returned object alive as long as the native side would need it.

Example:

@interface NSMutableArray
+ (instancetype)arrayWithArray:(NSArray *)array;
- (void)sortUsingFunction:(NSInteger (*)(id, id, void *))compare context:(void *)context;
@end

When a function pointer is marshalled to JavaScript it is exposed as a JavaScript function.