Calculator App Lesson

I new here and am following along with the calculator app.

However the version of Xcode I’m using is newer than the lesson version and I’m struggling to work out the new syntax for the #Preview

I’ve tried this but it does not work ;

traits: .fixedLayout(width: 100, height: 100)
) {
CalculatorButton(label: “1”, colour: .gray)

What have I missed?



Hi Lee,

Welcome to the community.

Which View are you trying to get the preview to work with?

(edit) Try this for your CalculatorButton Preview

#Preview {
    CalculatorButton(label: "1", color: .gray)
        .previewLayout(.fixed(width: 100, height: 100))

I’m assuming that you have created the Calculator class which is the ObservableObject.

Hi Chris,

Thank you