You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sorry, I'm still a beginner. After removing nonisolated(unsafe), the code runs normally. Is this the correct approach, or is there a recommended solution?
I look forward to your response, thank you!
// `with(object, on: actor) { object, actor in ... }` hands the object over
// to the given actor and then invokes the callback within the actor.
#if compiler(<6)
@available(macOS 10.15, tvOS 13.0, iOS 13.0, watchOS 6.0, *)
@_unsafeInheritExecutor
internal func with<A: Actor, Value: ThreadConfined>(
_ value: Value, on actor: A,
_ block: @Sendable @escaping (isolated A, Value) async throws -> NotificationToken
) async rethrows -> NotificationToken {
if value.realm == nil {
fatalError("Change notifications are only supported for managed objects")
}
let tsr = ThreadSafeReference(to: value)
let config = Unchecked(wrappedValue: value.realm!.rlmRealm.configurationSharingSchema())
return try await actor.invoke { actor in
if Task.isCancelled {
return nil
}
let scheduler = RLMScheduler.actor(actor, invoke: actor.invoke, verify: actor.verifier())
let realm = Realm(try! RLMRealm(configuration: config.wrappedValue, confinedTo: scheduler))
guard let value = tsr.resolve(in: realm) else {
return nil
}
// This is safe but 5.10's sendability checking can't prove it
// nonisolated(unsafe) can't be applied to a let in guard so we need
// a second variable
nonisolated(unsafe) let v = value
return try await block(actor, v)
} ?? NotificationToken()
}
Stacktrace & log output
'nil' is not compatible with closure result type'NotificationToken' (aka 'RLMNotificationToken')
Cannot find 'nonisolated'in scope
Cannot find 'unsafe'in scope
Consecutive statements on a line must be separated by ';'
Can you reproduce the bug?
Always
Reproduction Steps
Create a new Swift project and use CocoaPods to get the latest version of Realm (version 20.0.0).
Version
20.0.0
What Atlas Services are you using?
Local Database only
Are you using encryption?
No
Platform OS and version(s)
macOS Sonoma 14.5
Build environment
Xcode version: 15.2
Dependency manager and version: CocoaPods
The text was updated successfully, but these errors were encountered:
How frequently does the bug occur?
Always
Description
Sorry, I'm still a beginner. After removing nonisolated(unsafe), the code runs normally. Is this the correct approach, or is there a recommended solution?
I look forward to your response, thank you!
Stacktrace & log output
Can you reproduce the bug?
Always
Reproduction Steps
Create a new Swift project and use CocoaPods to get the latest version of Realm (version 20.0.0).
Version
20.0.0
What Atlas Services are you using?
Local Database only
Are you using encryption?
No
Platform OS and version(s)
macOS Sonoma 14.5
Build environment
Xcode version: 15.2
Dependency manager and version: CocoaPods
The text was updated successfully, but these errors were encountered: