Swift Cheatsheet

A quick reference guide for the Swift programming language covering the primary types, including Number, String, and Bool, and advanced data structures like Set, Array and Dictionary

cover

Comment

// This is a single-line comment

/*
This is a
multi-line comment
*/

Type Alias

typealias Integer = Int
let myInteger: Integer = 0

Variable, Constant, Type

// Declare a constant
let pi = 3.14159

// Declare a variable
var radius = 5.0

// Define a custom type
struct Circle {
    var radius: Double
    var area: Double {
        return pi * radius * radius
    }
}

// Convert between types
let diameter = Int(radius * 2)
let circle = Circle(radius: radius)