Programare swift Swift tutorial from tutorials point | Page 19
Swift 4
The individual tokens are:
print
(
"test!"
)
Comments
Comments are like helping texts in your Swift 4 program. They are ignored by the
compiler. Multi-line comments start with /* and terminate with the characters */ as shown
below:
/* My first program in Swift 4 */
Multi-line comments can be nested in Swift 4. Following is a valid comment in Swift 4:
/* My first program in Swift 4 is Hello, World!
/* Where as second program is Hello, Swift 4! */ */
Single-line comments are written using // at the beginning of the comment.
// My first program in Swift 4
Semicolons
Swift 4 does not require you to type a semicolon (;) after each statement in your code,
though it’s optional; and if you use a semicolon, then the compiler does not complain
about it.
However, if you are using multiple statements in the same line, then it is required to use
a semicolon as a delimiter, otherwise the compiler will raise a syntax error. You can write
the above Hello, World! program as follows:
import Cocoa
/* My first program in Swift 4 */
var myString = "Hello, World!"; print(myString)
Identifiers
A Swift 4 identifier is a name used to identify a variable, function, or any other user-
defined item. An identifier starts with an alphabet A to Z or a to z or an underscore _
followed by zero or more letters, underscores, and digits (0 to 9).
Swift 4 does not allow special characters such as @, $, and % within identifiers. Swift 4 is
a case sensitive programming language. Thus, Manpower and manpower are two
different identifiers in Swift 4. Here are some examples of acceptable identifiers:
7