Arrays 在数据生成之前启动Swift View
我的问题是:我正在附加一个数组,该数组用作我的组件的参数。组件在附加任何内容之前启动。函数数组在填充之前返回 我有以下代码:Arrays 在数据生成之前启动Swift View,arrays,swift,swiftui,Arrays,Swift,Swiftui,我的问题是:我正在附加一个数组,该数组用作我的组件的参数。组件在附加任何内容之前启动。函数数组在填充之前返回 我有以下代码: struct ContentView: View { //This gets data from a Firebase db @ObservedObject var categories = getData() func getCards() -> [AnimatedCard] { var array = [Animate
struct ContentView: View {
//This gets data from a Firebase db
@ObservedObject var categories = getData()
func getCards() -> [AnimatedCard] {
var array = [AnimatedCard]()
for i in categories.datas{
array.append(AnimatedCard(cardContentImage: "test1", cardContentTitle: i.name, itemHeight: 300,itemWidth: 300))
}
return array
}
var body: some View {
CarouselView(views: self.getCards())
}
}
- Firebase部件的工作方式是在列表中显示
i.name
获取一组动画卡。这也在起作用CarouselView
struct ContentView: View {
//This gets data from a Firebase db
@ObservedObject var categories = getData()
func getCards() -> [AnimatedCard] {
var array = [AnimatedCard]()
for i in categories.datas{
array.append(AnimatedCard(cardContentImage: "test1", cardContentTitle: i.name, itemHeight: 300,itemWidth: 300))
}
return array
}
var body: some View {
Group {
if self.categories.datas.count > 0 {
CarouselView(views: self.getCards())
}
}
}
}
您应该将条件嵌入到
组的正文中,否则它将无法编译。