Complex callback causes iOS to not build
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 1.9k
- Forks
- 117
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 44
Description
What's happening?
I have a bit of a more complicated callback structure and useage of hybrid objects. The code works completely fine on android, but on iOS it doesn't compile. Provided a sample repo to test with.
I am not sure if my swift code is actually just wrong (Barely know swift), but I don't think so.
Reproduceable Code
Repo: https://github.com/ronickg/bug
import type { HybridObject } from 'react-native-nitro-modules';
export interface ComplexData {
url: string;
statusCode: number;
headers: Record<string, string>;
metadata: string[];
}
export interface MyCallback {
onSimpleEvent(message: string): void;
onComplexEvent(data: ComplexData): void;
onDataReceived(data: ComplexData, buffer: ArrayBuffer): void;
onMaybeData(data: ComplexData | undefined): void;
onMultiParam(
data: ComplexData,
buffer: ArrayBuffer,
optional: ComplexData | undefined
): void;
}
export interface CallbackTester
extends HybridObject<{ android: 'kotlin'; ios: 'swift' }> {
createBuilder(callback: MyCallback): CallbackBuilder;
}
export interface CallbackBuilder
extends HybridObject<{ android: 'kotlin'; ios: 'swift' }> {
setMessage(msg: string): void;
trigger(): void;
}
Swift Code:
import Foundation
import NitroModules
class HybridCallbackTester: HybridCallbackTesterSpec {
func createBuilder(callback: MyCallback) throws -> any HybridCallbackBuilderSpec {
return HybridCallbackBuilder(callback: callback)
}
}
class HybridCallbackBuilder: HybridCallbackBuilderSpec {
private let callback: MyCallback
init(callback: MyCallback) {
self.callback = callback
}
private var message: String = "default"
func setMessage(msg: String) throws {
self.message = msg
}
func trigger() throws {
// Create complex test data
let complexData = ComplexData(
url: "https://example.com/test",
statusCode: 200,
headers: ["Content-Type": "application/json", "X-Custom": "value"],
metadata: ["meta1", "meta2", "meta3"]
)
// Create test ArrayBuffer
let testString = "Test data here!"
let buffer = ArrayBuffer.allocate(size: testString.utf8.count)
testString.utf8.enumerated().forEach { (index, byte) in
buffer.data[index] = byte
}
callback.onSimpleEvent(message)
callback.onComplexEvent(complexData)
callback.onDataReceived(complexData, buffer)
callback.onMaybeData(complexData)
callback.onMultiParam(complexData, buffer, nil)
}
}
Relevant log output
Sadly the error message doesn't really help much, just shows:
Command SwiftCompile failed with a nonzero exit code
Device
iPhone 13 Pro Max
Nitro Modules Version
0.31.0
Nitrogen Version
0.31.0
Can you reproduce this issue in the Nitro Example app here?
Yes, I can reproduce the same issue in the Example app here
Additional information
- I am using Expo
- I am using nitrogen
- I have read and followed the Troubleshooting Guide.
- I created a reproduction PR to reproduce this issue here in the nitro repo. (See Contributing for more information)
- I searched for similar issues in this repository and found none.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked reproduction repository and the Nitro Example app, then run the iOS build using the Swift callback definitions shown in the issue. Compare the compiler output for the complex callback methods and consider the issue complete when the reproduction builds on iOS as it already does on Android.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react-native, swift
- Domain
- mobile-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100