Exploring data types
All programming languages can store numbers, words, and logic states, and Swift is no different. Even if you're an experienced programmer, you may find that Swift represents these values differently from other languages that you may be familiar with.
For more information on data types, visit https://docs.swift.org/swift-book/LanguageGuide/TheBasics.html.
Let's walk through the Swift versions of integers, floating-point numbers, strings, and Booleans in the next sections.
Representing integers
Let's say you want to store the following:
- The number of restaurants in a city
- Passengers in an airplane
- Rooms in a hotel
You would use integers, which are numbers without a fractional component (including negative numbers).Integers in Swift are represented by the Int
type.
Representing floating-point numbers
Let's say you want to store the following:
- Pi (3.14159...)
- Absolute zero (-273.15 °C)
You would use floating-point numbers, which are numbers...