如何使 AppStorage 变量仅在 运行 on iOS 14 时可用?

How to make AppStorage Variable only available when running on iOS 14?

我要疯了我想使用仅在 iOS 14 中可用的 AppStorage(在小部件中使用它)!但是我得到一个错误:

Property wrappers are not yet supported on local properties

我想将小部件集成到我的 UIKit 应用程序中,将来会提供 属性 包装器吗?

现在我讨厌的解决方法是让整个 ViewController @available(iOS 14.0, *),但你猜对了,它现在只在 iOS 14 上运行!

@AppStorage("incomeTotal", store: UserDefaults(suiteName: "group.de.davidkoenig.SimpleMoney"))
var incomeTotal: String = "0.0"

上面是我的 AppStorage 代码。

也许你能帮帮我!?

我找到了一种在 UIKit 中保护对象的方法:

UserDefaults(suiteName: "group.de.davidkoenig.SimpleMoney")!.set(String(format: "%.2f", sumBalance), forKey: "balanceTotal")

这有效,在我的 SwiftUI 文件中我使用了问题中的代码!