HexLibraryHexLibrary
</> HexCodeSign inSign up
PythonJavaScriptTypeScriptCC++JavaPHPGoRustRubyBashSQLLuaPerlCOBOLPascalDelphiFortranDartSwiftC#JuliaGroovyRElixirHaskellKotlinScalaClassic ASPClipperMS-DOS
LESSONS
Introduction to SwiftVariablesData TypesOperatorsStringsArraysConditions (if / else)Loops (for / while)Functions
REFERENCE
📖 Overview
🖥️ Output
📦 Variables & Types
🔢 Numbers & Math
✍️ String
📚 Array & Dictionary
🔀 Condition & Loop
🧩 Function
Swift›Introduction to Swift

Introduction to Swift

First step into Apple's iOS/macOS language Swift: printing with print, comments, and simple syntax.

Simple enough for a 5-year-old to understand

Print with print

Swift is simple: no semicolons are needed, and a main function is not required. print outputs text to the screen and moves to the next line.

Your first program
1
print("Hello!")
Prints to the screen and moves to the next line.
Output / InputPrints to the screen and moves to the next line.
Output / Input
💡 Hint: In Swift, semicolons are not required at the end of lines.

Comment line

Example code
1
// This is a comment — does not run.
Single-line comment with //.
CommentSingle-line comment with //.
2
print("Code here")
Only this line runs.
Output / InputOnly this line runs.
CommentOutput / Input

🎯 Exercise & Practice

Test what you've learned — answer, write code, check instantly. (2 left)

1.What is needed at the end of a line in Swift?
2.Print exactly Hello World to the screen.

🎯 Expected output: Hello World

Loading editor…

About this topic

Swift is a programming language introduced by Apple in 2014 to replace Objective-C. Today, the vast majority of iPhone, iPad, Mac, Apple Watch, and Apple TV apps are written in Swift. The language is open-source and also runs on Linux, so it can be used on the server side as well.

Swift's design goal was to be "safe yet fast." Safety here is not an abstract word: the language catches null-pointer access, type mixing, and numeric overflow either at compile time or runtime. That's why many of the errors you encounter while learning Swift are actually moments where the language is protecting you.

Initially, the thing that surprises people the most is the compiler's strictness. Someone coming from Python might find it strange that they cannot add an integer and a float together. But this strictness is what prevents the app from crashing in the user's hands; getting the error while writing it today is better than getting it in the store tomorrow.

What you will learn

  • How a Swift program works
  • printing to the screen with print
  • String interpolation syntax
  • Writing comment lines
  • When a semicolon is necessary

Who is this for?

  • Those who want to write iOS or macOS apps
  • Those transitioning from Objective-C to Swift
  • Beginners who want to learn a modern, type-safe language

When to use?

Swift is the default way to develop apps in the Apple ecosystem: the UI with SwiftUI, concurrency with Swift Concurrency, all written in the same language.

It is possible to use Swift on non-Apple platforms, but community and library support is limited; Go or Node are more mature options for the server side.

Common mistakes

Wrong

println("Hello")

Swift 1 had println, but it was removed in Swift 2 and merged with print. Today, this code gives the error "cannot find 'println' in scope." You will frequently encounter this in older examples found on the internet; you need to check which version Swift examples belong to.

Correct

print("Hello")

Wrong

let name = "Ayşse"
print("Hello (name)")

Parentheses alone do not interpolate the variable's value into the text; it literally prints "Hello (name)" on the screen. In Swift, to put a value inside a string, a backslash must precede the parenthesis. This syntax is unique to Swift, and people coming from other languages constantly forget it.

Correct

let name = "Ayşse"
print("Hello \(name)")

Wrong

print("one") print("two")

Swift considers line breaks as statement boundaries, but if you write two statements on the same line, you need to put a semicolon between them. This code gives the error "consecutive statements on a line must be separated by ';'". The solution is usually not to add a semicolon, but to write the two statements on separate lines.

Correct

print("one")
print("two")

Frequently asked questions

Is a Mac required to learn Swift?

Practically yes for app development, because Xcode only runs on macOS and the iOS simulator is there too. But it is not mandatory to learn the language: Swift also runs on Linux and browser-based workspaces, you can try the basic syntax anywhere.

Should I use a semicolon at the end of the line?

No. Semicolons are optional in Swift, and the community has adopted a style of not using them. They are only mandatory if you write multiple statements on the same line, which is also a writing style not recommended for readability.

Can Swift and Objective-C be used in the same project?

Yes, the two can live side by side in the same project; Apple supports this with a bridging header file. Older projects are usually migrated to Swift gradually; it is not necessary to translate all the code overnight.

Summary

print prints to the screen; println no longer exists.

A backslash and parentheses are used to interpolate a value into a string.

Semicolons are only required between two statements on the same line.

Swift is open-source and also runs on Linux.

The compiler's strictness catches errors before runtime.

HexLibraryHexLibrary

Learn programming more clearly. Every command is explained line by line with colors, reinforced with runnable exercises, test your code instantly — all in one place, free.

Learn

  • Home
  • Languages & Lessons
  • HexCode

Company

  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

Other Projects

  • HexToolz
  • Free Service Manuals
© 2026 HexLibrary · The clearest way to learn code