Values in Swift
Swift has various value types including strings, integers, floats, booleans, etc. Here are a few basic examples.
To run the program, save it as values.swift
and use the Swift compiler:
In Swift, we don’t need to define a main()
function as the entry point of our program. The code is executed from top to bottom.
Swift uses print()
instead of fmt.Println()
for console output. The print()
function in Swift can handle multiple arguments and automatically adds spaces between them.
For string concatenation, Swift uses the +
operator, similar to many other languages.
Arithmetic operations in Swift are straightforward and similar to other C-style languages.
Boolean operations in Swift use the same operators as in many other programming languages: &&
for AND, ||
for OR, and !
for NOT.
Swift is a type-safe language, but it also has type inference, which means you don’t always need to explicitly declare the type of a variable or constant.