Can’t preview my file because: Type of expression is ambiguous without a type annotation

I want to preview my file but can’t because of this error: Type of expression is ambiguous without a type annotation. im using Xcode beta 16 and target iOS 18

import SwiftUI

struct WorkoutStartView: View {
    @Binding var workout: Workout?
    
    var body: some View {
        VStack {
           // my code
    }
}


#Preview {
    let sampleExercises: [Exercise] = [
        Exercise(name: "Sit-ups", imageName: "sitUps", difficulty: 3, guidelines: "Test guidelines for crunches.", muscle: "Upper"),
        
        Exercise(name: "Leg raises", imageName: "legRaises", difficulty: 3, guidelines: "Test guidelines for reverse crunches.", muscle: "Lower"),
        
        Exercise(name: "L-sit", imageName: "lSit", difficulty: 3, guidelines: "Test guidelines for flutter kicks.", muscle: "6 Pack"),
        
        Exercise(name: "Side jack-knives", imageName: "sideJackKnives", difficulty: 3, guidelines: "Test guidelines for sitting twists.", muscle: "Obliques"),
        
        Exercise(name: "Dead bug", imageName: "deadBug", difficulty: 3, guidelines: "Test guidelines for knee to elbow.", muscle: "Complete"),
        
        Exercise(name: "Wipers", imageName: "wipers", difficulty: 3, guidelines: "Test guidelines for half wipers.", muscle: "Core"),
        
        Exercise(name: "Long arm cruches", imageName: "longArmCrunches", difficulty: 4, guidelines: "Test guidelines for crunches.", muscle: "Upper"),
        
        Exercise(name: "Pulse ups", imageName: "pulseUps", difficulty: 4, guidelines: "Test guidelines for reverse crunches.", muscle: "Lower"),
        
        Exercise(name: "Star plank", imageName: "starPlank", difficulty: 4, guidelines: "Test guidelines for flutter kicks.", muscle: "6 Pack")
    ]
    
    @State var sampleWorkout: Workout? = Workout(
    name: "Morning Routine",
    difficulty: 3,
    workingTime: 30,
    recoveryTime: 30,
    isSet: false,
    duration: 8
    )
    
    sampleWorkout!.exercises = sampleExercises
    WorkoutStartView(workout: $sampleWorkout).preferredColorScheme(.dark)
}

sorry for the bigs code blocks but wanted my error to be reproducible.
here are the two classes implied implementation:

@Model
class Workout: Identifiable {
    var id: UUID
    var name: String
    var difficulty: Int
    var workingTime: Int
    var recoveryTime: Int
    var count: Int
    var duration: Int
    var isSet: Bool
    var setNumber: Int?
    var restTime: Int?
    
    // Define a one-to-many relationship with Exercise
    @Relationship(deleteRule: .cascade, inverse: Exercise.workout) var exercises: [Exercise]? = [Exercise]()
    
    init(name: String, difficulty: Int, workingTime: Int, recoveryTime: Int, isSet: Bool, duration: Int, setNumber: Int? = nil, restTime: Int? = nil) {
        self.id = UUID()
        self.name = name
        self.difficulty = difficulty
        self.count = 0
        self.duration = duration
        self.workingTime = workingTime
        self.recoveryTime = recoveryTime
        self.isSet = isSet
        self.setNumber = setNumber
        self.restTime = restTime
    }
    
    func difficultySymbol() -> Image {
        switch difficulty {
        case 1:
            return Image(systemName: "circle.fill")
        case 2:
            return Image(systemName: "triangle.fill")
        case 3:
            return Image(systemName: "square.fill")
        case 4:
            return Image(systemName: "hexagon.fill")
        case 5:
            return Image(systemName: "star.fill")
        default:
            return Image(systemName: "flame.fill")
        }
    }
    
    func ToString() -> String {
        var res = "(name) - (difficultySymbol()) - (workingTime)n"
        for exercise in exercises! {
            res += "t(exercise.name)n"
        }
        return res
    }
}

@Model
class Exercise: Identifiable, Equatable {
    var id: UUID
    var name: String
    var imageName: String
    var difficulty: Int
    var guidelines: String
    var muscle: String
    
    // Define the relationship back to Workout
    var workout: Workout?

    init(name: String, imageName: String, difficulty: Int, guidelines: String, muscle: String, workout: Workout? = nil) {
        self.id = UUID()
        self.name = name
        self.imageName = imageName
        self.difficulty = difficulty
        self.guidelines = guidelines
        self.muscle = muscle
        self.workout = workout
    }
    
    static func == (lhs: Exercise, rhs: Exercise) -> Bool {
        return lhs.name == rhs.name
    }
    
    func hash(into hasher: inout Hasher) {
            hasher.combine(name)
        }
    
    var image: Image {
        Image(imageName)
    }
    
    var muscleImg: Image {
        Image(muscle)
    }
    
    func difficultySymbol() -> Image {
        switch difficulty {
        case 1:
            return Image(systemName: "circle.fill")
        case 2:
            return Image(systemName: "triangle.fill")
        case 3:
            return Image(systemName: "square.fill")
        case 4:
            return Image(systemName: "hexagon.fill")
        case 5:
            return Image(systemName: "star.fill")
        default:
            return Image(systemName: "flame.fill")
        }
    }
    
    func toString() -> String {
        return "(name) - (muscle) - (difficulty)"
    }
}

Of course, I tried to type annotate all my variable but nothing fixed.

I waited too much code so I have to write more to post this code. ignore this please.

New contributor

Leandro is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

Can’t preview my file because: Type of expression is ambiguous without a type annotation

I want to preview my file but can’t because of this error: Type of expression is ambiguous without a type annotation. im using Xcode beta 16 and target iOS 18

import SwiftUI

struct WorkoutStartView: View {
    @Binding var workout: Workout?
    
    var body: some View {
        VStack {
           // my code
    }
}


#Preview {
    let sampleExercises: [Exercise] = [
        Exercise(name: "Sit-ups", imageName: "sitUps", difficulty: 3, guidelines: "Test guidelines for crunches.", muscle: "Upper"),
        
        Exercise(name: "Leg raises", imageName: "legRaises", difficulty: 3, guidelines: "Test guidelines for reverse crunches.", muscle: "Lower"),
        
        Exercise(name: "L-sit", imageName: "lSit", difficulty: 3, guidelines: "Test guidelines for flutter kicks.", muscle: "6 Pack"),
        
        Exercise(name: "Side jack-knives", imageName: "sideJackKnives", difficulty: 3, guidelines: "Test guidelines for sitting twists.", muscle: "Obliques"),
        
        Exercise(name: "Dead bug", imageName: "deadBug", difficulty: 3, guidelines: "Test guidelines for knee to elbow.", muscle: "Complete"),
        
        Exercise(name: "Wipers", imageName: "wipers", difficulty: 3, guidelines: "Test guidelines for half wipers.", muscle: "Core"),
        
        Exercise(name: "Long arm cruches", imageName: "longArmCrunches", difficulty: 4, guidelines: "Test guidelines for crunches.", muscle: "Upper"),
        
        Exercise(name: "Pulse ups", imageName: "pulseUps", difficulty: 4, guidelines: "Test guidelines for reverse crunches.", muscle: "Lower"),
        
        Exercise(name: "Star plank", imageName: "starPlank", difficulty: 4, guidelines: "Test guidelines for flutter kicks.", muscle: "6 Pack")
    ]
    
    @State var sampleWorkout: Workout? = Workout(
    name: "Morning Routine",
    difficulty: 3,
    workingTime: 30,
    recoveryTime: 30,
    isSet: false,
    duration: 8
    )
    
    sampleWorkout!.exercises = sampleExercises
    WorkoutStartView(workout: $sampleWorkout).preferredColorScheme(.dark)
}

sorry for the bigs code blocks but wanted my error to be reproducible.
here are the two classes implied implementation:

@Model
class Workout: Identifiable {
    var id: UUID
    var name: String
    var difficulty: Int
    var workingTime: Int
    var recoveryTime: Int
    var count: Int
    var duration: Int
    var isSet: Bool
    var setNumber: Int?
    var restTime: Int?
    
    // Define a one-to-many relationship with Exercise
    @Relationship(deleteRule: .cascade, inverse: Exercise.workout) var exercises: [Exercise]? = [Exercise]()
    
    init(name: String, difficulty: Int, workingTime: Int, recoveryTime: Int, isSet: Bool, duration: Int, setNumber: Int? = nil, restTime: Int? = nil) {
        self.id = UUID()
        self.name = name
        self.difficulty = difficulty
        self.count = 0
        self.duration = duration
        self.workingTime = workingTime
        self.recoveryTime = recoveryTime
        self.isSet = isSet
        self.setNumber = setNumber
        self.restTime = restTime
    }
    
    func difficultySymbol() -> Image {
        switch difficulty {
        case 1:
            return Image(systemName: "circle.fill")
        case 2:
            return Image(systemName: "triangle.fill")
        case 3:
            return Image(systemName: "square.fill")
        case 4:
            return Image(systemName: "hexagon.fill")
        case 5:
            return Image(systemName: "star.fill")
        default:
            return Image(systemName: "flame.fill")
        }
    }
    
    func ToString() -> String {
        var res = "(name) - (difficultySymbol()) - (workingTime)n"
        for exercise in exercises! {
            res += "t(exercise.name)n"
        }
        return res
    }
}

@Model
class Exercise: Identifiable, Equatable {
    var id: UUID
    var name: String
    var imageName: String
    var difficulty: Int
    var guidelines: String
    var muscle: String
    
    // Define the relationship back to Workout
    var workout: Workout?

    init(name: String, imageName: String, difficulty: Int, guidelines: String, muscle: String, workout: Workout? = nil) {
        self.id = UUID()
        self.name = name
        self.imageName = imageName
        self.difficulty = difficulty
        self.guidelines = guidelines
        self.muscle = muscle
        self.workout = workout
    }
    
    static func == (lhs: Exercise, rhs: Exercise) -> Bool {
        return lhs.name == rhs.name
    }
    
    func hash(into hasher: inout Hasher) {
            hasher.combine(name)
        }
    
    var image: Image {
        Image(imageName)
    }
    
    var muscleImg: Image {
        Image(muscle)
    }
    
    func difficultySymbol() -> Image {
        switch difficulty {
        case 1:
            return Image(systemName: "circle.fill")
        case 2:
            return Image(systemName: "triangle.fill")
        case 3:
            return Image(systemName: "square.fill")
        case 4:
            return Image(systemName: "hexagon.fill")
        case 5:
            return Image(systemName: "star.fill")
        default:
            return Image(systemName: "flame.fill")
        }
    }
    
    func toString() -> String {
        return "(name) - (muscle) - (difficulty)"
    }
}

Of course, I tried to type annotate all my variable but nothing fixed.

I waited too much code so I have to write more to post this code. ignore this please.

New contributor

Leandro is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật