提问人:Complete Athletic 提问时间:12/13/2022 更新时间:12/13/2022 访问量:79
调用没有参数的表达式中缺少参数参数 #1
Missing Argument Parameter #1 in Call for an expression with no parameters
问:
当我尝试在锻炼列表中调用 ForEach 时,我不断收到错误“调用中缺少参数 #1 的参数”,我不知道 Swift 对什么感到困惑。我相信它与它引用的 ViewModel 有关,但我不确定如何明确地告诉它。
这是我的视图代码:
struct WorkoutProgramView: View {
@ObservedObject var workoutViewModel: WorkoutViewModel
@StateObject var vm: WorkoutListViewModel = .init()
@State var currentWeek: [Date] = []
@State var currentDay: Date = Date()
@State var selection: String? = nil
let screenSize: CGRect = UIScreen.main.bounds
let columns = [GridItem(.adaptive(minimum: 150, maximum: 400))]
var body: some View {
ScrollView{
LazyVGrid(columns: columns){
ForEach(vm.workoutDays, id:\.id) { day in
if isSameDay(date1: currentDay, date2: day.date!){
ZStack{
RoundedRectangle(cornerRadius: 5).frame(width: .infinity).padding().foregroundColor(Color.black).opacity(0.1)
}
我在 ForEach 行上收到错误。
这是我的 workoutViewModel 和 vm:
import SwiftUI
@MainActor
class WorkoutListViewModel: ObservableObject{
@ObservedObject var workoutViewModel = WorkoutViewModel()
@Published var workoutDays: [WorkoutDays] = []
func loadWorkoutData() async throws{
let svc = NestedFirestoreService(workoutViewModel: workoutViewModel)
self.workoutDays = try await svc.retrieveWorkoutDays()
}
}
class WorkoutViewModel: ObservableObject {
let auth = Auth.auth()
let user = Auth.auth().currentUser
@Published var name: String = ""
@Published var date: Date = Date()
@Published var exercise: Double = 0.0
@Published var workoutProgramList: [WorkoutProgramModel] = []
@Published var todaysFoodList: [FoodItem] = []
@Published var workoutProgramSelected: String = ""
@Published var workoutDayData: [WorkoutDays] = []
@Published var workoutDaySelected: String = ""
@Published var exerciseData: [ExerciseModel] = []
@Published var ExerciseSelected: String = ""
@Published var loggedSet: Int = 0
@Published var loggedReps: Int = 0
@Published var loggedWeight: Int = 0
@Published var notes: String = ""
@Published var dayAndExerciseList: [newStrengthModel] = []
}
这是我的 WorkoutDays 模型“:
struct WorkoutDays: Encodable, Decodable, Identifiable {
@DocumentID var id: String?
var name: String?
var date: Date?
var description: String?
var timeToCompleteWarmup: Double?
var timeToCompleteStrength: Double?
var timeToCompleteMetcon: Double?
var timeToCompleteAccessories: Double?
var exercises: [ExerciseModel]?
}
struct ExerciseModel: Encodable, Decodable, Hashable, Identifiable {
@DocumentID var id: String?
var workoutDayID: String?
var name: String?
var reps: [Int]?
var percent: [Double]?
var linkToVideo: String?
var isCompleted: Bool?
var description: String?
var timeToComplete: Double?
var type: String?
}
谁能帮忙?已经坚持了好几天了,它肯定会让我烦恼,哈哈。
答: 暂无答案
评论
ObservableObject
@ObservedObject
class
View
@DocumentID