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