πŸš€ 8.9 Released! β†’ ⚑️ New Node-API Engine Preview, πŸ“² ns widget ios, πŸ’… Tailwind v4 and more...
Read Announcement

You can add Objective-C/Swift source files to App_Resources/iOS/src. For Objective-C files, create a .modulemap file. To add a CocoaPod, edit App_Resources/iOS/Podfile:

bash
App_Resources/
β”œβ”€iOS/
β”‚β”œβ”€src/
β”‚β”‚β”œβ”€Shimmer.swift
β”‚β”‚β”œβ”€Shimmer.h
β”‚β”‚β”œβ”€Shimmer.m
││└─module.modulemap
│└─Podfile
└─...more

Adding Swift code ​

Define the swfit file in App_Resources/iOS/src.

swift
// HelloSwift.swift
importUIKit

classHelloSwift: NSObject {
@objcpublicvar stringToReturn: String="Hello from Swift!"

@objcpublicfuncgetString() ->String {
return stringToReturn;
 }
}

Given the example above, your JavaScript or TypeScript code can reference the Swift code by using the full class name:

ts
consthelloSwift=newHelloSwift()
helloSwift.stringToReturn ='Custom hello from Swift!'
console.log(helloSwift.getString()) 
// prints: Custom hello from Swift!

Using @objc ​

@objc allows exposing variables and functions to use them from JS/TS, note that in the example the variables and methods have this notation.

Using @objcMembers ​

A shortcut to the @objc notation is to use the @objcMembers notation at the class level to make the entire class accessible.

swift
// HelloSwift.swift
importUIKit

@objcMembers
classHelloSwift: NSObject {
publicvar stringToReturn: String="Hello from Swift!"

publicfuncgetString() ->String {
return stringToReturn;
 }
}

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /