ios - SwiftUI - 正确使用 @available() 和 #available
问题描述
我在以下代码中遗漏了什么吗?
此应用程序构建(macOS Monterey b5 / Xcode 13 b5)并在 iOS 15 设备上完美执行——但在 iOS 14.7 设备上导致 SIGABRT...
import SwiftUI
struct ContentView: View {
@State private var text = "This app causes a runtime error on ios 14.7"
@available(iOS 15.0, *)
@FocusState var isInputActive: Bool
var body: some View {
if #available(iOS 15.0, *) {
TextEditor(text: $text)
.focused($isInputActive)
} else { // ios14 or <
TextEditor(text: $text)
}
}
}
解决方案
推荐阅读
- python - 将用户输入从子窗口传递到父窗口 python tkinter
- css - 使用 css 创建图标而不是使用图像
- c# - 读取包含 OLE 嵌入对象的 RTF 文件
- google-chrome-app - 安装 chrome 应用程序时出错 - 内容安全策略指令“script-src”包含无效源:“wasm-eval”
- javascript - 当在文件名中包含块哈希时,webpack 在 publicPath 中设置哈希会导致错误?
- java - 使用 Java 将数组转换为 Spark DataFrame 中的 DenseVector
- angular - Angular中的单元测试,测试组件未定义
- c++ - 如何通过文件扩展名引用文件夹中的文件
- listview - Flutter:ListViews 和其他 Scrollables 如何确定它们的大小?
- c# - 如何使用 C# 向下滚动到 appium 中的特定元素