Writing Your First TurboModule in Swift

youtube-cover
Teachers
Oskar Kwaśniewski
Software Developer
@
Callstack

React Native’s New Architecture makes TurboModules the default path for extending functionality. In this tutorial, Oskar walks through the full workflow: bootstrapping the project, exploring Codegen output, writing the Swift implementation, adding an Objective‑C bridge, and verifying the module inside a real app.

Bootstrapping the library with React Native Builder Bob

Oskar starts by creating an Expo project and using Builder Bob to scaffold a TurboModule library. This generates platform folders, a starter TypeScript spec, and default native code. Highlight the moment where he swaps the default multiply method for the Local Storage API (setItem, getItem, removeItem, clear).

Understanding the TypeScript spec and Codegen contract

The TypeScript spec defines the contract between JS and native. Codegen reads this file during pod install to produce Objective‑C/C++ headers that ensure type‑safe communication. Oskar shows where these headers live in Xcode and how they directly mirror the TypeScript definitions.

Navigating generated code in Xcode

Once expo prebuild and pod install run, the iOS folder appears with generated native targets. Oskar demonstrates how to locate the TurboModule inside the Pods hierarchy and why Xcode must build once before symbols resolve.

Implementing the business logic in Swift

The core logic lives in Swift: a NativeLocalStorage class backed by UserDefaults with a custom suite name. Oskar walks through the implementation of each method, including potential pitfalls (Swift types unsupported by Objective‑C).

Bridging Swift to Objective‑C

TurboModules require an Objective‑C layer. Oskar shows how to import the generated Swift header, create an instance variable, initialize it in init, and forward calls from Objective‑C into Swift. He discusses why attributes like @objcMembers are required for visibility.

Testing the TurboModule in an Expo application

The episode concludes with adding simple UI buttons that call the TurboModule from JavaScript. Oskar demonstrates setting a value, retrieving it, and verifying persistence via breakpoints in Xcode.

Resources

Learn how to build a fully working TurboModule in Swift, integrate it with Codegen, and bridge it through Objective‑C inside an Expo app.

Heading 1

Heading 2

Heading 3

Heading 4

Heading 5
Heading 6

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.

Block quote

Ordered list

  1. Item 1
  2. Item 2
  3. Item 3

Unordered list

  • Item A
  • Item B
  • Item C

Text link

Bold text

Emphasis

Superscript

Subscript

TurboModules feel powerful but risky?

We help teams use them with confidence in real production apps.

Let’s chat
Link copied to clipboard!
//
Insights

Learn more about React Native

Stay up to date with our latest insights on React, React Native, and cross-platform development from the people who build the technology and scale with it daily.

//
insights

Learn more about React Native

//
React Native

We can help you move
it forward!

At Callstack, we work with companies big and small, pushing React Native everyday.

React Native Performance Optimization

Improve React Native apps speed and efficiency through targeted performance enhancements.

On-device AI

Run AI models directly on iOS and Android for privacy-first experiences with reliable performance across real devices.

AI Knowledge Integration

Connect AI to your product’s knowledge so answers stay accurate, up to date, and backed by the right sources with proper access control.

Generative AI App Development

Build and ship production-ready AI features across iOS, Android, and Web with reliable UX, safety controls, and observability.