在我的 Catalyst 项目中,我想将 SidebarListStyle()
仅应用于 Mac。
我的问题是我无法构建项目,即使在检查操作系统时也是如此。这是一个例子:
struct CrossList: View {
#if targetEnvironment(macCatalyst)
var body: some View {
List {
Text("Mac Test")
}
.listStyle(SidebarListStyle())
}
#else
var body: some View {
List {
Text("iOS Test")
}
}
#endif
}
构建时出现以下错误:
'SidebarListStyle' is unavailable in iOS
最佳答案
Mac Catalyst 本质上是 iOS – 只是在 Mac 上运行。 SidebarListStyle
仅在开发完整的 macOS(非 Catalyst)应用程序时可用,并且将包含在编译器指令 #if os(macOS)
中,如下所示:
struct CrossList: View {
#if os(macOS)
var body: some View {
List {
Text("Mac Test")
}
.listStyle(SidebarListStyle())
}
#else
var body: some View {
List {
Text("iOS Test")
}
}
#endif
}
关于ios - 仅将 SidebarListStyle() 应用于 Mac,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58883496/