0Pricing
Swift Academy · Lesson

Numbers, Booleans and Characters

Working with Int, Double, Float, Bool, and Character types.

Numbers, Booleans and Characters is a free Swift Academy lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Swift Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Welcome

Swift has a rich set of built-in numeric types, a Boolean type, and a Character type for representing single Unicode scalars. Let's explore each.

Integer Types

Swift provides signed and unsigned integers at various bit widths: ```swift let a: Int = -42 // platform width (64-bit) let b: Int8 = 127 let c: UInt = 255 let d: UInt8 = 200 ``` Use `Int` for general-purpose integers; sized types when memory layout matters.

Int.min and Int.max

Every integer type exposes its bounds: ```swift print(Int.min) // -9223372036854775808 on 64-bit print(Int.max) // 9223372036854775807 print(UInt8.max) // 255 ``` Overflowing these bounds is a runtime error (use overflow operators &+, &- for intentional overflow).

Floating-Point: Double and Float

```swift let pi: Double = 3.14159265358979 // 64-bit, ~15 decimal digits let e: Float = 2.71828 // 32-bit, ~6 decimal digits ``` Prefer `Double` for most work. Use `Float` only when memory size is critical (e.g. large arrays of values).

Arithmetic Operators

Swift supports the standard arithmetic operators: ```swift let sum = 10 + 3 // 13 let diff = 10 - 3 // 7 let prod = 10 * 3 // 30 let quot = 10 / 3 // 3 (integer division) let rem = 10 % 3 // 1 ``` Remember: dividing two Ints truncates toward zero.

Boolean Type: true and false

```swift var isLoggedIn: Bool = false isLoggedIn = true if isLoggedIn { print("Welcome back!") } ``` Swift Booleans are strict — you cannot use integers as truthy/falsy values like in C.

Boolean Operators

The three core Boolean operators: ```swift let a = true && false // AND → false let b = true || false // OR → true let c = !true // NOT → false ``` Short-circuit evaluation: in `&&` the right side is only evaluated if the left is `true`.

Character Type

A `Character` holds a single extended grapheme cluster (a human-readable character): ```swift let letter: Character = "A" let emoji: Character = "🚀" let accented: Character = "é" ``` Character literals use double quotes, just like String.

Characters vs Strings

A `String` is a sequence of `Character` values: ```swift let str = "Hello" for ch in str { print(ch) // H, e, l, l, o } ``` You can build a String from Characters with `String(character)` or by appending to a var String.

Numeric Overflow Operators

When you need intentional overflow (e.g. hardware bit manipulation), use overflow operators: ```swift var x: UInt8 = 255 x = x &+ 1 // wraps to 0 instead of crashing ``` The `&+`, `&-`, `&*` operators never trap on overflow.

Quick Check

Which Swift Boolean operator returns `true` only when **both** operands are `true`?

Recap

Key takeaways: • Integers: `Int` for general use, sized types (`Int8`, `UInt8`…) when needed • Floats: `Double` (64-bit) preferred; `Float` (32-bit) for space-sensitive arrays • `Bool` is strict — only `true`/`false`, no integer coercion • `Character` holds one Unicode grapheme cluster • Use `&+`, `&-`, `&*` for intentional overflow Next: strings and interpolation.

Frequently asked questions

Is the “Numbers, Booleans and Characters” lesson free?

Yes — the full text of “Numbers, Booleans and Characters” is free to read here on the web, and the Swift Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Swift Academy course, upgrade to CoddyKit PRO.

What will I learn in “Numbers, Booleans and Characters”?

Working with Int, Double, Float, Bool, and Character types. You practise Swift Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Swift Academy?

No prior experience is required. Swift Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Numbers, Booleans and Characters” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Swift Academy lesson?

Yes. Every Swift Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. let vs var: Constants and Variables
  2. Type Inference and Explicit Types
  3. Numbers, Booleans and Characters
  4. String Fundamentals and Interpolation
← Back to Swift Academy