In Swift, there are two ways to add comments:
1. Single-line comments: These comments start with two forward slashes “//” and extend to the end of the line. Anything written after the “//” will not be executed as code and is ignored by the compiler.
Example:
// This is a single-line comment
var age = 27 // This is also a single-line comment
2. Multiline comments: These comments start with a forward slash and an asterisk “/*” and end with an asterisk and a forward slash “*/”. Anything written between these markers will be ignored by the compiler.
Example:
/* This is
a multiline
comment */
var name = "John"
It’s good practice to add comments to your code to explain what your code is doing, making it easier for yourself or other developers to read and understand the code later on.