100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Swift

Data Types in Swift

Explore Swift's core data types—Int, Double, Float, Bool, String, Character, and tuples—and how Swift handles numeric type safety.

BasicsBeginner7 min readJul 8, 2026
Analogies

Introduction

Swift is a type-safe language, meaning every value has a known type at compile time and the compiler checks that types match wherever they are used. The fundamental data types include Int for whole numbers, Double and Float for floating-point numbers, Bool for true/false values, String for text, and Character for a single grapheme cluster. Swift also provides tuples, a lightweight way to group multiple values of possibly different types into a single compound value.

🏏

Cricket analogy: Swift's type safety is like a scorer who won't let you add a boundary count (Int) directly to a batting average (Double) without an explicit conversion; player names are Strings, a single jersey-number digit is a Character, whether a review upheld is a Bool, and a tuple like (name: String, runs: Int) bundles a batsman's name and score together without needing a full struct.

Syntax

swift
let age: Int = 30
let price: Double = 19.99
let ratio: Float = 0.5
let isActive: Bool = true
let name: String = "Ada"
let initial: Character = "A"
let point: (Int, String) = (1, "first")

Explanation

Int represents whole numbers and, on modern platforms, is 64-bit by default. Double offers 64-bit floating-point precision and is Swift's preferred type for decimal numbers, while Float offers 32-bit precision. Bool holds only true or false. String represents text as a collection of Character values, and Character represents a single extended grapheme cluster. Unlike some languages, Swift does not perform implicit conversion between numeric types: an Int and a Double cannot be combined in an expression without an explicit conversion, which prevents subtle precision-loss bugs. Tuples, written as a comma-separated list in parentheses like (Int, String), let you bundle related values together without defining a full struct.

🏏

Cricket analogy: A run total is naturally an Int, 64-bit by default on modern platforms, while a batting average uses Double's 64-bit precision rather than Float's 32-bit for accuracy; a wicket-fallen flag is a Bool, a player's name is a String made of Character grapheme clusters, and Swift won't silently combine that Int run count with the Double average — you must convert explicitly, just as a tuple (name: String, average: Double) bundles the two without a full struct.

Example

swift
let itemCount = 3          // Int
let unitPrice = 2.5        // Double
// let total = itemCount * unitPrice   // Error: Int and Double cannot be combined
let total = Double(itemCount) * unitPrice

let coordinates: (Int, Int) = (10, 20)
print(coordinates.0, coordinates.1)
print(total)

Output

swift
10 20
7.5

Key Takeaways

  • Swift's core types include Int, Double, Float, Bool, String, and Character.
  • Swift does not implicitly convert between numeric types like Int and Double.
  • Explicit conversion, such as Double(someInt), is required to mix numeric types.
  • Double is generally preferred over Float for its greater precision.
  • Tuples group multiple values of possibly different types, e.g. (Int, String).
  • Every value in Swift has a well-defined type checked at compile time.

Practice what you learned

Was this page helpful?

Topics covered

#Swift#SwiftProgrammingStudyNotes#Programming#DataTypesInSwift#Data#Types#Syntax#Explanation#StudyNotes#SkillVeris