Skip to content
Learn Netverks

Lesson

Step 8/36 22% through track

types-swift

Types in Swift

Last reviewed Jun 1, 2026 Content v20260601
Track mode
server_compiled
Means
Compiled runner
Reading
~1 min
Level
beginner

This lesson

This lesson teaches Types in Swift: the syntax, patterns, and safety habits you need before advancing in Swift.

Teams still ship Types in Swift in Swift codebases—skipping it leaves gaps in debugging and code reviews.

You will apply Types in Swift in contexts like: iPhone/iPad/Mac apps, server-side Swift (niche), and Apple toolchain projects.

Write Swift in main.swift with print(), click Run on server—the dev runner swiftc compiles and runs the binary (requires Swift toolchain, typically macOS; LEARNING_RUNNER_ENABLED=true).

When you can explain the previous lesson's ideas without copying starter code.

Swift’s type system is strict and expressive—numeric types, strings, booleans, and custom structs/enums all participate in compile-time checking with type inference.

Basic types

  • Int, Double, Float, Bool — numbers and logic
  • String — Unicode text (value semantics with copy-on-write optimization)
  • Character — single extended grapheme cluster
  • Integer sizes: Int8, UInt, etc., when you need explicit width

Type safety

let a: Int = 10
let b: Double = 10.0
// let sum = a + b  // compile error — must convert explicitly

Unlike JavaScript, Swift will not silently coerce incompatible numeric types.

Important interview questions and answers

  1. Q: Int vs Int32?
    A: Int matches the platform word size (64-bit on modern Apple devices); use sized integers for binary protocols and interop.
  2. Q: Is Swift dynamically typed?
    A: No—types are checked at compile time, with inference reducing annotation noise.

Self-check

  1. Can you add Int and Double without conversion?
  2. What type does true have?

Tip: Swift will not silently add Int and Double—convert explicitly like in strict typed languages.

Interview prep

Int vs Double addition?

Must convert explicitly—no silent numeric coercion.

Dynamic typing?

No—Swift is statically typed with inference.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • Int vs Int64?
  • Any vs AnyObject?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump