Integrating ChatGPT in Your iOS Apps - Non-sendable/nonisolated error in tutorial

Performing the tutorial in Lesson 1 Demo playground I get the following issue on client.sendChats…:

Non-sendable result type ā€˜GPTChatResponse’ cannot be sent from non isolated context in call to instance method ā€˜sendChats’

Does anyone know why this is happening and how to fix it.

My develop environment is Sequoia 15.4.1 / Xcode 16.3 on a Mac mini.

I resolved the issue.

When I performed the Lesson 1 Demo I cut and pasted the code from the video transcript because I didn’t see any kind of of starter project link. I got the

Non-sendable result type ā€˜GPTChatResponse’ cannot… error

which I couldn’t resolve. I have since found the link to the project materials. On comparison of the code sources I found no significant differences between my Demo code and the project materials, but the Demo Final playground works as advertised!

I then found that the Playground Settings/Swift version is Swift 5 for the downloaded materials, but for my Demo playground is Swift 6. Changing my Demo playground setting to Swift 5 eliminates the error and allows the Demo to work.

Conclusion: Apparently changes in Swift 6 to concurrent environment sendable/non-sendable and isolated/non-isolated classes handling breaks Swift 5 code. The code would still need to be modified in some way in order to compile if Swift 6.

Hello ryan247zook!

Thank you for your response.

I did as you suggested and made GPTChatResponse conform to Sendable, but it just changes the error to:

Sending main actor-isolated ā€˜client’ to nonisolated instance method ā€˜sendChats’ risks causing data races between nonisolated and main actor-isolated uses

My attempts to make ā€˜sendChats’ isolated only led to a cascade of errors. I suspect that a more serious reworking of the code is required for Swift 6.