Basic Syntax in Swift
In this tutorial, we will learn the basic syntax of Swift language. We will go through the key components of a simple Swift program.
Swift Program
import Foundation
print("Hello, World!")
Output
Hello, World!
Basic Syntax of a Swift Program
import Foundation
This line imports the Foundation framework, which provides fundamental data types, protocols, and functions for Swift programs.print("Hello, World!")
This line uses theprint
function to output the string "Hello, World!" to the standard output (usually the console).
Key Points to Remember
- All Swift statements must end with a semicolon (
;
), although it's often omitted and optional. - Swift is case-sensitive, meaning that
print
andPrint
would be considered different. - Comments can be added using
//
for single-line comments or/* ... */
for multi-line comments. - Swift is known for its safety features, concise syntax, and powerful features for building iOS, macOS, watchOS, and tvOS applications.