Converting function value of type @MainActor Error

Can someone tell me why in the sample code below I am getting the error:

Converting function value of type '@MainActor (WebServices.User) -> CKRecord' to '(WebServices.User) -> CKRecord' loses global actor 'MainActor'

on this line:

try await deleteRecord(record: user, createRecord: createUserRecord)

I don't understand the error. If I pass in appSettings to WebServices I don't get this error, but if I have appSettings as an @EnvironmentObject I get this error.

Thanks.

import SwiftUI
import CloudKit

class WebServices: ObservableObject {
	@EnvironmentObject var appSetting: AppSettings
	private var publicDatabase : CKDatabase?

	struct User: Identifiable, Hashable {
		var username: String
		var id: String = UUID().uuidString
	}

	func deleteUser(user: User) async throws {
		try await deleteRecord(record: user, createRecord: createUserRecord)
	}

	private func createUserRecord(user:User) -> CKRecord {
		return CKRecord(recordType: "User", recordID: CKRecord.ID(recordName: "username"))
	}

	func deleteRecord<RecordType: Hashable>(record: RecordType, createRecord: @escaping ((RecordType) -> CKRecord)) async throws {
		let ckRecord = createRecord(record)
		_ = try await publicDatabase?.deleteRecord(withID: ckRecord.recordID)
	}
}
Post not yet marked as solved Up vote post of zach.m Down vote post of zach.m
644 views

Replies

I have the same question. hope someone would clarify.