How to integrate Node.js TypeScript library into native iOS application?

I need to incorporate a TypeScript library from npm into my iOS native application. Right now I don’t have enough time to create a native Swift version of this functionality, so I’m looking for a temporary solution.

My current approach is to create a Swift bridge that communicates with the TypeScript code running inside a hidden WKWebView. The TypeScript package would handle the business logic while my native UIKit interface manages the user experience. I chose WKWebView over JSContext because it provides better support for standard web APIs.

I’m wondering about potential issues with this setup. Are there any performance concerns I should expect? How much will this impact my app’s size? Could this cause problems during Apple’s app store review process? I know this isn’t the best long-term solution, but it’s what I need to do for now.

Having gone through a similar integration, I can confirm that WKWebView serves well as a temporary solution. However, it’s crucial to monitor memory usage, as WKWebView can consume significant amounts of RAM. If possible, ensure you’re releasing resources when they’re no longer needed.

Keep in mind that performance can lag if large datasets are frequently passed between Swift and JavaScript; consider batching your data transfers or implementing a queuing system to enhance efficiency.

Regarding the App Store review, I haven’t experienced issues using this method. Just ensure your TypeScript code doesn’t attempt to dynamically load additional scripts, which may raise concerns. Your app’s bundle size will heavily rely on your npm dependencies, ranging between 1MB to 10MB based on what you include.

Using TypeScript in a WKWebView can serve as a viable interim solution for your iOS app. I’ve employed this method in the past and found that while performance can indeed suffer slightly due to the Swift/JavaScript bridge, it typically remains acceptable unless processing substantial real-time data. Expect an increase in your app size by approximately 2-3MB, contingent on the complexity of your TypeScript library. Ensure your JavaScript is well-structured to avoid potential flags during the App Store review, and implement robust error handling in your bridge to mitigate silent failures.

Been there! Main issue I hit was debugging - when something breaks in the webview, you’re flying blind. Set up console logging that bridges back to Xcode first thing, or you’ll hate yourself later. Also, WKWebView has serious mem leak issues. It holds onto objects way longer than it should.