Cookcademy 1 - Build the Recipe Model

Here are the instructions:

With your new description property above, you can create some small test instances to ensure that it’s working correctly.

let myIngredient = Ingredient(name: "Sugar", quantity: 2.0, unit: Unit.tbs)print(myIngredient.description) // "2 Tablespoons Sugar"

Where do you enter this to get results? In the lesson you are working in a model file…

Just test by typing print(myIngredient) and see if it comes out as expected.

Where do you type in print(myIngredients)? And where does “it come out”? I

When I type it into the recipe.swift file, I just get errors and there is no output screen. Is it supposed to output to the console? Or is there a test screen/feature?

Hi,

It’s hard to know specifically where you are writing this from the original post. That’ll better inform what kind of techniques you can use to test/debug. Are you using text editor, Codecademy environment, xcode?

Can you link to the exercise?

Also as a sanity check try commenting out some code and just printing some normal sentence.

print("hello, world!")

Thanks for your help and quick responses!

I am in Xcode. I am following the lesson Cookcademy 1 Build the Recipe Model.

The directions are to enter all of this in an xcode model file called recipe.Swift in a project called cookcademy. In the project no edits have been made to the contentView files or cookcademyApp.swift file. So anything I type into these files results in errors.

The default contentView.Swift file does print out “Hello World” Because it’s in its default state.

When I type print(“Hello World”) in the recipe file it says “Expressions are not allowed at the top level.”

So far I have not seen lessons on debugging so I don’t know how to do that.

Debugging is just a fancy way for fixing code to make it work.

Take a gander here and see if it helps: xcode - 'Expressions are not allowed at the top level' if the module is not main.swift - Stack Overflow

Ok thanks for the link, but that was not helpful. I am very new to this. I don’t have a main.swift file and I don’t think this is a “command line based project”, but I guess I don’t really know.

I have created and edited exactly one file in this project. When I enter the code it tells me to enter, I get errors. There is no example or sample that they include that works.

I’m not sure what to do next to make this part work.