Swift Complete Guide 🍏

iOS App Development Language

1. What is Swift?

Swift is a programming language developed by Apple used to build iOS, macOS, watchOS, and tvOS apps.

2. Hello World

import Foundation

print("Hello Swift")

3. Variables

var name = "Sasank"
let age = 18

4. Data Types

Int, String, Double, Bool

5. If-Else

let age = 18

if age >= 18 {
    print("Adult")
} else {
    print("Minor")
}

6. Loops

for i in 1...5 {
    print(i)
}

7. Functions

func add(a: Int, b: Int) -> Int {
    return a + b
}

8. OOP in Swift

class Car {
    var model: String

    init(model: String) {
        self.model = model
    }

    func drive() {
        print("Car is moving")
    }
}

9. Optionals

var name: String? = "Apple"

if let unwrapped = name {
    print(unwrapped)
}

10. iOS UI (SwiftUI)

import SwiftUI

struct ContentView: View {
    var body: some View {
        Text("Hello iOS")
    }
}

11. Mini Projects