Data Types (int,char,bool) that looks cool.

Data Types, Since Swift, is a new programming language for iOS, macOS, watchOS, and tvOS app development. Swift provides its own versions of all fundamental C and Objective-C types, including Int for integers, Double and Float for floating-point values, Bool for Boolean values, and String for textual data.

Swift is a type-safe language, which means the language helps you to be clear about the types of values your code can work with. If part of your code requires a String, type safety prevents you from passing it an Int by mistake. Likewise, type safety prevents you from accidentally passing an optional String to a piece of code that requires a non-optional String.

Data Types

Int or UInt − This is used for whole numbers. More specifically, you can use Int32, Int64 to define 32 or 64 bit signed integers, whereas UInt32 or UInt64 to define 32 or 64-bit unsigned integer variables. For example, 42 and -23.

Float − This is used to represent a 32-bit floating-point number and numbers with smaller decimal points. For example, 3.14159, 0.1, and -273.158.

Double − This is used to represent a 64-bit floating-point number and used when floating-point values must be very large. For example, 3.14159, 0.1, and -273.158.

Bool − This represents a Boolean value that is either true or false.

String − This is an ordered collection of characters. For example, “Hello, World!”

Character − This is a single-character string literal. For example, “C”

Optional − This represents a variable that can hold either a value or no value.

Tuples − This is used to group multiple values in a single Compound Value.

Integer types

32-bit platform, Int is the same size as Int32.

64-bit platform, Int is the same size as Int64.

32-bit platform, UInt is the same size as UInt32.

64-bit platform, UInt is the same size as UInt64.

Int8, Int16, Int32, Int64 can be used to represent 8 Bit, 16 Bit, 32 Bit, and 64 Bit forms of a signed integer.

UInt8, UInt16, UInt32, and UInt64 can be used to represent 8 Bit, 16 Bit, 32 Bit and 64 Bit forms of unsigned integer.

Datatypes

Data TypesExampleDescription
Character“s”,”a”a 16-bit Unicode character
String“hello world!”represents textual data
Int3, -23an integer number
Float2.4, 3.14, -23.21represents 32-bit floating-point number
Double2.422342412represents 64-bit floating-point number
Booltrue and falseAny of two values: true or false

Integers

VariantSizeRange
Int88 bit-128 to 127
Int1616 bit-215 to 215-1
Int3232 bit-231 to 231-1
Int6464 bit-263 to 263-1
UIntDepends on platform0 to 232(32-bit platform) 0 to 264(64-bit platform)

Double to store the number with more precision (up to 15 decimal places)
Float to store the number with less precision (up to 6 decimal places)

Stay always with right Data types 🙂


Discover more from CODE t!ps

Subscribe to get the latest posts sent to your email.

Scroll to Top

Discover more from CODE t!ps

Subscribe now to keep reading and get access to the full archive.

Continue reading