【发布时间】:2021-10-13 18:32:27
【问题描述】:
struct RandomizeTab: View {
var restaurantInfo = Restaurants()
var body: some View {
NavigationView {
NavigationLink(
destination: DetailView(restaurantInfo: restaurantInfo.restaurantList[Int.random(in: 0...restaurantInfo.restaurantList.count-1)]),
label: {
Text("Randomize")
.font(.title3)
.fontWeight(.bold)
.padding()
.background(Color.red)
.foregroundColor(.white)
.clipShape(Capsule())
})
}
}
}
目前,此代码从列表中随机选择一家餐厅,并且每次点击它时都不会从列表中选择一家新的随机餐厅。
【问题讨论】:
-
数组有随机元素方法
标签: swift mvvm swiftui xcode12