iOS Swift – A Beginner to Advanced Guide with Examples
Swift is Apple’s official programming language for building apps on iOS, macOS, watchOS, and tvOS. Since its introduction in 2014, Swift has quickly become the preferred language for developers due to its speed, safety, and modern syntax. If you’re planning to build iOS apps, mastering Swift is essential.
💡 What is Swift?
Swift is a type-safe, fast, and expressive programming language created by Apple. It’s designed to work with Apple’s frameworks like Cocoa Touch and SwiftUI. Swift is also open-source, meaning you can use it outside the Apple ecosystem too.
🔹 Why Choose Swift for iOS Development?
🛠 Basic Swift Syntax Example
Let’s start with a Hello World program in Swift:
import UIKit
print("Hello, Swift!")
📌 Explanation:
📌 Example 1: Variables & Constants in Swift
let name = "JustAcademy" // Constant
var age = 5 // Variable
print("Welcome to \(name), we are \(age) years old!")
Output:
Welcome to JustAcademy, we are 5 years old!
📌 Example 2: Functions in Swift
func greet(user: String) -> String {
return "Hello, \(user)! Welcome to Swift."
}
print(greet(user: "Roshan"))
Output:
Hello, Roshan! Welcome to Swift.
📌 Example 3: iOS Swift – Button Action in a Simple App
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var label: UILabel!
@IBAction func buttonTapped(_ sender: UIButton) {
label.text = "Button Pressed!"
}
}
📌 Explanation:
📚 Learn iOS Swift with JustAcademy
If you want to master Swift for iOS development, JustAcademy offers a complete iOS training course where you’ll:
🔮 Final Thoughts
Swift is the future of iOS development — fast, safe, and developer-friendly. If you learn Swift, you unlock the potential to create iPhone, iPad, Mac, Apple Watch, and Apple TV apps with one skill set.