Logo
Swift Basics
Swift BasicsData Types

Data Types

Swift offers a rich set of built-in data types for various kinds of data manipulation. Understanding these data types is crucial for effective Swift programming. This section will explore the most commonly used data types in Swift, such as Int, Double, String, and Bool.

Integer Types

What is Int?

Int is used for storing integer values. It can store both positive and negative numbers.

var age: Int = 30

UInt for Unsigned Integers

UInt is used for storing unsigned integer values, which are always positive or zero.

var stockQuantity: UInt = 50

Floating-Point Types

Double and Float

Double and Float are used for storing floating-point numbers, with Double having more precision.

var pi: Double = 3.14159
var height: Float = 1.75

String Type

String is used for storing text.

var name: String = "John"

Boolean Type

Bool is used for storing true or false values.

var isCompleted: Bool = false

Conclusion

Understanding the different data types in Swift allows you to choose the most appropriate type for your variables and constants, making your code more efficient and readable.

Book a conversation with us for personalize training today!

Was this helpful?
Logo