Swift Overview

Understanding Swift programming language fundamentals

🍎 What is Swift?

Swift is Apple's modern programming language introduced in 2014. It combines performance with safety, making iOS and macOS development faster and more reliable than ever before.


// Swift is simple and powerful
let message = "Swift makes coding fun!"
print(message)
                                    

Output:

Swift makes coding fun!

Swift Key Features

🛡️

Type Safety

Prevents common programming errors

let age: Int = 25
// Type is enforced

Fast Performance

Optimized for speed and efficiency

// Compiled to native code
func calculate() -> Int {
    return 10 * 5
}
🎯

Optionals

Handle missing values safely

var name: String? = nil
// Safe handling of nil
🔧

Automatic Memory

No manual memory management

class Person {
    let name: String
    init(name: String) {
        self.name = name
    }
}

🔹 Swift vs Other Languages

How Swift compares to popular programming languages:

Swift Advantages:

  • vs Objective-C: Cleaner syntax, better performance
  • vs Java: More concise, type inference
  • vs Python: Faster execution, compiled language
  • vs JavaScript: Type safety, better tooling
// Swift syntax is clean and readable
struct User {
    let name: String
    let age: Int
    
    func greet() -> String {
        return "Hello, I'm \(name) and I'm \(age) years old"
    }
}

let user = User(name: "Alice", age: 30)
print(user.greet())

Output:

Hello, I'm Alice and I'm 30 years old

🔹 Swift Platforms

Where you can use Swift:

🔸 iOS Development

import UIKit

class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        print("iOS app is ready!")
    }
}

🔸 macOS Development

import Cocoa

class AppDelegate: NSObject, NSApplicationDelegate {
    func applicationDidFinishLaunching(_ notification: Notification) {
        print("macOS app launched!")
    }
}

🔸 Server-Side Swift

import Foundation

// Swift can run on servers too!
let server = HTTPServer()
server.start()

🔹 Swift Version History

Swift has evolved rapidly since 2014:

  • Swift 1.0 (2014): Initial release
  • Swift 2.0 (2015): Error handling, guard statements
  • Swift 3.0 (2016): Major syntax changes
  • Swift 4.0 (2017): Codable protocol
  • Swift 5.0 (2019): ABI stability
  • Swift 5.5+ (2021+): Async/await, actors

🧠 Test Your Knowledge

When was Swift first released?