Type Aliases in Swift
Swift Aliases provides a feature to help users provide another name for an existing type.
The syntax used to define the type aliases is as given below.
typealias newname = type
Example:
In this example, the statements tell the compiler that Marks is another name for Int.
typealias Marks = Int
The given code works perfectly fine and provides an integer variable named Physics.
typealias Marks = Int
var Physics: Marks = 95
print(Physics)
Output:
95
Type Safety in Swift
Once a variable is defined of a type, you can not give it some value of another type. This means the Swift is a type-safe language.
So, the code is checked at the compile-time, and it gives an error in case it doesn’t work well.
Example-
var x = 7
x = "Coding Ninjas"
print(x)
Output-
main.swift:2:11: error: cannot assign value of type 'String' to type 'Int'
x = "Coding Ninjas"
Built-in Data Types
Swift 4 programming language provides many data types to store information in a variable or constant. These are explained as follows-
Integer
- Swift integer data type allows the user to store and represent integer numbers with no fractional part.
- The “Int” keyword is used to declare the variables.
- The default value for it is 0.
- The platform type decides the size of the data type. It can be either 32 bits or 64 bits.
- There are variations of Int to define unsigned integer type. This is done using UInt32, UInt64, etc., where 32 and 64 are the bits for the platform used. Similarly, Int32 and Int64 are used for signed integer types.
Example:
var mark:Int = 70
print(mark)
mark = 80
print(mark)
Output:
70
80
Boolean
- Swift Boolean data type stores only two values, either true or false.
- The keyword “Bool” is used to declare the variable.
- The default value is false.
Example:
let result: Bool = true
print(result)
Output:
true
Float
- Swift float is used to store and represent the fractional values.
- The keyword “ Float” is used to declare the variable.
- The size of this data type is 32-bit.
- The default value is 0.0.
Example:
let max_value: Float = 98.99
print(max_value)
Output:
98.99
Double
- Swift double data type is also used to store the fractional value, but it has more decimal points than float.
- It uses the “Double” keyword to declare the values.
- The default value is 0.0.
- The size of this data type is 64-bit.
Example:
let more_points: Double = 39.009769651432
print(more_points)
Output:
39.009769651432
Character
- Swift character data type represents and stores a single character string.
- It uses the keyword “Character” to declare values.
- It is also used to add emojis.
Example:
let your_name: Character = "G"
print(your_name)
Output:
G
String
- Swift string data type is used to store and represent the set of characters or a group of meaningful text.
- It uses the keyword “String” to declare values.
- The default value is “”.
Example:
let website_name: String = "Coding Ninjas"
print(website_name)
Output:
Coding Ninjas
Range Table

Frequently Asked Questions
What is Optional in built-in data types in Swift?
Optional describes the variables which can hold a particular value or no value.
What are Tuples in built-in data types in Swift?
When we have to group multiple values in a single Compound Value, tuples are used.
Does Swift provide type inference?
Yes, Swift provides type inference, i.e., during compile time, the compiler automatically knows the type of data using the given values by the user.
Conclusion
In this article, we have extensively discussed the data types of Swift. We started with a brief introduction of Swift data types, their size, features, key points, and examples.
After reading about the data types of Swift, are you not feeling excited to explore more articles on the topic of Swifts? Don’t worry; Coding Ninjas has you covered. To learn, see Swift Tuples, Swift recursion, Swift methods, Swift Strings, Swift Arrays, Swift Dictionary, etc.
To study more about data types, refer to Abstract Data Types in C++.
Do upvote our blogs if you find them helpful and engaging!
Happy learning!