Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non Sendable Types #21

Open
JCKL opened this issue Apr 21, 2023 · 1 comment
Open

Non Sendable Types #21

JCKL opened this issue Apr 21, 2023 · 1 comment

Comments

@JCKL
Copy link

JCKL commented Apr 21, 2023

When I run this sample code In Xcode 14.3. I get the following warnings:

  • /sample-cloudkit-sharing/Sharing/ViewModels/ViewModel.swift:74:68 Non-sendable type '[CKRecordZone]' passed in implicitly asynchronous call to main actor-isolated function cannot cross actor boundary
  • /sample-cloudkit-sharing/Sharing/ViewModels/ViewModel.swift:74:73 Non-sendable type 'CKRecordZone' in asynchronous access to main actor-isolated property 'recordZone' cannot cross actor boundary
  • /sample-cloudkit-sharing/Sharing/ViewModels/ViewModel.swift:91:32 Non-sendable type 'CKRecord' returned by call from main actor-isolated context to non-isolated instance method 'save' cannot cross actor boundary
  • /sample-cloudkit-sharing/Sharing/ViewModels/ViewModel.swift:91:32 Non-sendable type 'CKRecord' exiting main actor-isolated context in call to non-isolated instance method 'save' cannot cross actor boundary
  • /sample-cloudkit-sharing/Sharing/ViewModels/ViewModel.swift:107:36 Non-sendable type '[CKRecord]' exiting main actor-isolated context in call to non-isolated instance method 'modifyRecords(saving:deleting:savePolicy:atomically:)' cannot cross actor boundary
  • /sample-cloudkit-sharing/Sharing/ViewModels/ViewModel.swift:111:46 Non-sendable type 'CKRecord' returned by call from main actor-isolated context to non-isolated instance method 'record(for:)' cannot cross actor boundary
  • /sample-cloudkit-sharing/Sharing/ViewModels/ViewModel.swift:160:46 Capture of 'zone' with non-sendable type 'CKRecordZone' in a @Sendable closure
  • /sample-cloudkit-sharing/Sharing/ViewModels/ViewModel.swift:175:67 Non-sendable type '[CKRecordZone]' returned by call from main actor-isolated context to non-isolated instance method 'allRecordZones()' cannot cross actor boundary
  • /sample-cloudkit-sharing/Sharing/ViewModels/ViewModel.swift:191:36 Non-sendable type '[CKRecordZone]' exiting main actor-isolated context in call to non-isolated instance method 'modifyRecordZones(saving:deleting:)' cannot cross actor boundary

Until CKRecord, CKRecordZone become Sendable Types, what is a workaround for this sample code?

@gongzhang
Copy link

// DIRTY workaround ⚠️

extension CKRecord: @unchecked Sendable {
}

extension CKRecordZone: @unchecked Sendable {
}

I believe a better solution could be defining a sendable Contact struct and replacing the raw CKRecord in ViewModel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants