Type safety

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:

  1. 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.

  1. 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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.104.29