WhoBuilt

Writing Your First TurboModule in Swift

Dec 22, 2025· 18 min· 1.2K views·Watch on YouTube

Speaker

Oscar, a Callstack presenter, introduces a series on building React Native TurboModules and walks through a Swift local storage module.

TurboModules and Codegen

Oscar introduces a series covering Swift, Kotlin, and C++ TurboModules, along with JSI and Codegen. He explains that Codegen reads TypeScript module specs and generates native boilerplate, creating a typed contract between JavaScript and native code.

Set up the local storage module

Using React Native Builder Bob, Oscar creates an Expo project and a local TurboModule library. Its TypeScript spec defines four methods: setItem, getItem, removeItem, and clear. He runs Expo prebuild and installs CocoaPods to generate the iOS project and Codegen files.

Implement storage in Swift

Oscar inspects the generated Objective-C protocol and adds the required methods to the module. He implements the storage logic in Swift with Foundation's UserDefaults, using a suite name to keep this module's values separate. The methods map to UserDefaults operations for reading, writing, removing, and clearing values.

Bridge Swift to Objective-C and verify

Oscar marks the Swift class and methods with @objc so Objective-C can call them, then imports the generated Swift header and forwards each module method to the Swift implementation. He updates the JavaScript exports and tests saving and retrieving “Hello Expo” under the key “greeting.” The value appears in an alert and persists across reloads.

Takeaways

  • Define the module contract in TypeScript and let Codegen generate the native protocol.
  • Keep module logic in Swift and use a small Objective-C layer to connect it to React Native.
  • Expose Swift classes and methods to Objective-C with @objc and compatible types such as String.
  • After adding Swift files, update the podspec and reinstall CocoaPods.
  • Test the native bridge by saving and retrieving a value, then checking that it survives reloads.

Mentioned in this talk

Search inside this talk

What was claimed 4

  • feature
    TurboModules: Built for React Native's New Architecture
    “TurboModules are the new build system built from the ground up for the New Architecture.”
    YouTube
    Unverified1 source· Talk
  • feature
    code generation: Generates native boilerplate from TypeScript module specs
    “It defines a contract between your TypeScript files and your native code, then generates boilerplate code”
    YouTube
    Unverified1 source· Talk
  • uses
    Expo uses Pods
    “To install pods in Expo, we first have to do a prebuild.”
    YouTube
    Unverified1 source· Talk
  • feature
    Callstack: Channel publishing the video series
    “subscribe to the Callstack channel”
    YouTube
    Unverified1 source· Talk

Related talks