realm-swift icon indicating copy to clipboard operation
realm-swift copied to clipboard

Xcode 15 Beta 8: New Non-Sendable Warning for Actor-Based Realm Init

Open bdkjones opened this issue 10 months ago • 6 comments

How frequently does the bug occur?

Always

Description

Xcode 15 Beta 8 generates a new warning when you use Realm's suggested initialization pattern for an Actor-based realm:

actor MyActor
{
    private var realm: Realm!   // implicitly unwrapped so we can pass `self` to -Realm(actor:) within init.

    init() {
        realm = try await Realm(actor: self)   // WARNING: Non-sendable type 'Realm' returned by implicitly asynchronous call to nonisolated function cannot cross actor boundary
    }
}

Stacktrace & log output

N/A

Can you reproduce the bug?

Always.

NB: I have the strict concurrency checking build option set to complete. That may be necessary to see the warning.

Reproduction Steps

Create an actor-isolated Realm by following the pattern recommended in the documentation, as above.

Version

10.42.0

What Atlas Services are you using?

Local Database only

Are you using encryption?

No

Platform OS and version(s)

macOS 13.5.2

Build environment

Xcode version: Xcode 15 Beta 8 Dependency manager and version: SPM

bdkjones avatar Sep 11 '23 00:09 bdkjones

Note: changing the import statement to @preconcurrency import RealmSwift does remove this warning, but it's not clear that this is correct—RealmSwift does offer concurrency support via actors, etc.

bdkjones avatar Sep 12 '23 05:09 bdkjones

don't you need to specify actor: in the init?

aehlke avatar Jan 20 '24 14:01 aehlke

I have the same problem while using the example here: https://www.mongodb.com/docs/realm/sdk/swift/use-realm-with-actors/#define-a-custom-realm-actor

crisanvlad avatar Jan 22 '24 18:01 crisanvlad