← All courses

Xcode and Swift Basics

🗓 May 31, 2026 ⏱ 1 min read

Create a project

Open Xcode → Create New ProjectApp. Choose SwiftUI for the interface and Swift for the language. Press the ▶ button to run it in the Simulator.

Swift in five minutes

// Variables and constants
var score = 10        // can change
let name = "Anand"    // cannot change

// Functions
func greet(_ person: String) -> String {
    return "Hi, \(person)!"
}

// Optionals (a value that may be nil)
var nickname: String? = nil
print(nickname ?? "No nickname")  // default if nil

Why optionals matter

Swift forces you to handle “no value” safely. The ? means it might be empty, and ?? gives a fallback — this prevents a whole class of crashes.