Swift: Basics

Basics of Swift:

Let’s begin with the basics of Swift.

Basic print() method in Swift:

One or more values are printed to the terminal using the print() function.

print("Welcome to Swift!")
 
// Prints: Welcome to Swift!

Basic Program Structure in Swift:

From top to bottom, the programs runs line by line:

  • Line 1 prints Hello
  • Line 2 prints Swift World!
print("Hello")
print("Swift World!")

Single-line Comments:

Two consecutive forward slashes are used to make single-line comments in Swift. Any text after // on the same line is ignored by the compiler.


// This is a single-line comment an it will be ignored by the compiler.

Multiline Comments:

Multiline comments are written by beginning the comment with /* and ending it with */. Any text in between is ignored by the compiler.

/* 
This is a multi-line comment
all of this will be ignored by
the compiler

*/

Helpful Tools:

Here are some useful tools to help you along your journey!

Setting up an IDE (Integrated Development Environment) can be difficult for beginners. The Online Compiler will enable you to run your code inside your browser without the need to install an IDE. If you need a more detailed explanation of a specific topic, the best place to find answers is in the Official Documentation.

Scroll to Top
%d bloggers like this: