admin管理员组

文章数量:1123384

I'm wondering how to solve the Main actor-isolated class property 'current' can not be referenced from a nonisolated context Swift 6 issue inside a Swift Package.

In this package, I'm exposing a public struct that collects some device information. Unfortunately, now the UIDevice class is only accessible as @MainActor and the information I want to expose should be used even from parallel threads.

All the collected information can be eventually be calculated/collected at the start of the application that uses the package but I'm wondering how to do this properly.

This is a rough example of the current state:

public struct DeviceInfo: Codable, Equatable {

    let someVariable: String

    public static var current: APIDeviceInfo {
        DeviceInfo(
            // This is rising the issue `Main actor-isolated class property 'current' can not be referenced from a nonisolated context`
            someVariable: UIDevice.current...
        )
    }
}

My objective is to use this structure even from non-main threads.

本文标签: swiftSolve Main actorisolated static property inside a PackageStack Overflow