Integrating with iOS Applications

Builds provide downloadable artifacts for integrating your calculations with Objective-C.

This is done using JavaScriptCore support for iOS

We have provided Objective-C sample code but there is nothing to stop you from using this to integrate with Swift code. You can find the sample source here: ios-integration-objc-jscore-example

Build the project with the Objective-C option

In order to have the artifacts you need to check Objective-C in the Build Options. Navigate to Deployment, click Option and check Objective-C, see below:


Download the Build Artifacts

Once you have done the build, download the build result: navigate into the build (click into it) and open the Objective-C tab:


Import the required files into an XCode Project

Assuming you already have an XCode project set up, follow the import instructions within the zip archive.

  1. Import the JS bundle - the file that contains the actual calculations - into your project.
  2. Import the Objective-C header and class source files.

The ObjC files are wrappers that give you an interface into the JS calculations. The parameters of the call are to be provided as NSString-s, these will be converted by the engine to the proper math domains specified in your Calculation API.

Give it a try

Assuming you have done the Getting Started tutorial, you should have the Mortgage Project set up and you could easily do the followings.

Set up a test scenario

According to the followings our monthly payment should be 1168.29 (some currency) when the Score=620, T(term)=30 and P(principal) is 200 000.


Download and import into XCode

Following the download and import instructions, your project layout should look like this: The screen shot below also shows the code you could put into the didFinishLaunchingWithOptions method.


If you wanted to cut and paste, here is the source

#import "FormulatorBundle/MortgageCalculations.h"

and the didFinishLaunchingWithOptions part:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    // initialize bundle (JSContext)
    MortgageCalculations *mortgageCalculationsInstance = [MortgageCalculations sharedInstance];

    // initialize input values
    NSMutableDictionary * input = [[NSMutableDictionary alloc] init];
    NSString * client_score_value = @"620";
    NSString * term_value = @"30";
    NSString * principal_value = @"200000";
    input[@(MORTGAGE_PMT_FROM_SCORE__PMT__CLIENT_SCORE)] = client_score_value;
    input[@(MORTGAGE_PMT_FROM_SCORE__PMT__TERM)] = term_value;
    input[@(MORTGAGE_PMT_FROM_SCORE__PMT__PRINCIPAL)] = principal_value;

    // call calculation
    NSDictionary * result = [mortgageCalculationsInstance doCalculation:MORTGAGE_PMT_FROM_SCORE__PMT

    NSLog(@"calculation results:%@", result);

    return YES;

Run the project

Running the project, you see the same result as in the test case :)