Jump to

While doing programming in any language, we need different types of variables to store the information, and data types specify the type of data that can be stored inside a variable.

So, based on the type of data of a variable, the operating system actually allocates the memory and decides what can be stored in reserved memory or not.

Swift offers a collection of built-in data types. Each and everything is associated with data type. 

In general terms, a data type is the type of data a variable or constant can store in it. These are the data types that we found in other programming languages as well.  

Swift also offers a variety of other data types such as Array, Set, etc. (a.k.a Collection Types). Let’s discuss the basic data types in detail.

Bool

It can store only two values i.e. either True or False.  

Default value : false 

import Foundation  

var n = 10  

var flag = false  

if(n == 20) {  

 flag = true  

}  

print(flag)  

Output : true

Character

It is a single character string literal.  

import Foundation  

var str = "H"  

print(str)  

Output : H

String

It is the ordered collection of characters. They are used to display text in an app. It is  wrapped in double quotes and also known as String Literal.

Default value : ” ” (Empty string) 

import Foundation  

var str = "Hello"  

print(“\(str)”)  

Output : Hello

Int or UInt

It can store Whole numbers both positive and negative including 0, No fractional  part allowed.  

Default value : 0 

Int can store both positive and negative small numbers.  

UInt can store only unsigned numbers i.e. positive or 0. 

import Foundation  

var number = 10  

print(number)  

Output : 10

Float

It can store numbers with fractional components, representing 32 bit floating point number. 

Default value : 0.0

import Foundation  

var number = 20.46474  

print(number)  

Output : 20.46474

Double

It can store numbers with fractional components as Float but with larger floating  point values, representing 64 bit floating point number. 

Default value : 0.0 

import Foundation  

var n = 100.2323737321212121  

print(n)  

Output : 100.2323737321212121

Range of datatype variables:

TYPE BIT WIDTH RANGE
Int8 1 Byte -127 to 127
UInt8 1 Byte 0 to 255
Int32 4 Bytes -2147483648 to 2147483647
UInt32 4 Bytes 0 to 4294967295
Int64 8 Bytes -9223372036854775808 to 9223372036854775807
UInt64 8 Bytes 0 to 18446744073709551615
Float 4 Bytes 1.2E-38 to 3.4E+38 (~6 digits)
Double 8 Bytes 2.3E-308 to 1.7E+308 (~15 digits)

So, these are the built-in and most known data types.  Apart from using these data types, we have Tuples, Optionals, etc. We’ll discuss those in detail in the next few articles.

We hope you got the idea of the different data types in Swift. If you are looking for challenging opportunities at some of the fastest-growing global companies, join Talent500. 

 

Leave a Comment

Your email address will not be published. Required fields are marked *

You may also like

10 Resume Mistakes That Are Costing You Job Offers

Your resume serves as your pathway to securing job interviews, yet it will work against you. Your resume contains common errors that prevent you from getting job offers despite your

Illustration of a candidate in a professional home office setting speaking on a video call, with a laptop screen showing a virtual interviewer and practice tools representing InterviewIQ

Virtual Interview Tips That Actually Work

The growing trend of remote work has established virtual interviews as standard practice. The process of achieving virtual interview success requires specific preparation for candidates applying for remote positions and

Illustration of GCC leaders reviewing talent analytics dashboards and employer branding metrics that highlight career growth, retention, and EVP insights for 2026

Employer Branding & EVP Pulse Report 2026

Why GCCs Must Win the Talent Narrative Global Capability Centers in India have moved past the point where compensation alone can win the talent war. With over 1,900 GCCs and

Categories
Interested in working with Mobile ?

These roles are hiring now.

Loading jobs...
Scroll to Top