Swift is a type-safe language. It checks to see whether you're assigning values of the correct type to variables and flags mismatched types as errors. Let's see how this works:
- Enter the following code and run it:
// Type safety
restaurantRating = "Good"
Here, you are trying to assign a string to a variable of type Double. This is a type mismatch and you'll see a red circle with an exclamation mark inside it:
The exclamation mark means Xcode can't suggest a fix for this.
- Comment out the line by typing two / characters in front of it so it no longer causes an error in your program:
// Type safety
// restaurantRating = "Good"
Now that you know how to store data in constants and variables, let's look at how to perform operations on them.