Swift 扩展AppStorage以与Int32兼容
我想使用AppStorage属性包装器将CLAuthorizationStatus存储在用户默认值中,这样我就可以在整个应用程序中作为一个简单变量访问它,而不是每次都通过CLLocationManager访问授权状态。 问题在于,此枚举rawValue类型是Int32(而不是类似Int的UNAuthorizationStatus),因此以下情况不起作用:Swift 扩展AppStorage以与Int32兼容,swift,swiftui,rawrepresentable,appstorage,Swift,Swiftui,Rawrepresentable,Appstorage,我想使用AppStorage属性包装器将CLAuthorizationStatus存储在用户默认值中,这样我就可以在整个应用程序中作为一个简单变量访问它,而不是每次都通过CLLocationManager访问授权状态。 问题在于,此枚举rawValue类型是Int32(而不是类似Int的UNAuthorizationStatus),因此以下情况不起作用: @AppStorage("locationSettings") var locationSettings: CLAutho
@AppStorage("locationSettings") var locationSettings: CLAuthorizationStatus = CLAuthorizationStatus.notDetermined
抛出:候选者要求类型“CLAuthorizationStatus.RawValue”(又名“Int32”)和“Int”等效(要求指定为“Value.RawValue”==“Int”)(SwiftUI.AppStorage)
我尝试扩展AppStorage以包含一个初始值设定项,该初始值设定项具有一个以Int32作为rawValue的RawRepresentable,但我找不到要在其中包含什么来使其工作
extension AppStorage {
init(wrappedValue: Value, _ key: String, store: UserDefaults? = nil) where Value : RawRepresentable, Value.RawValue == Int32 {
}
}
提前谢谢