• Home
  • Basics
  • DSA
  • MAD
  • Concept
  • Practice
  • Misc
    • Tips
    • QA’s
    • Misc
  • Course
  • Home
  • Basics
  • DSA
  • MAD
  • Concept
  • Practice
  • Misc
    • Tips
    • QA’s
    • Misc
  • Course
  • APPS |
  • News |
  • WWDC |
  • I/O |
  • Ignite |
  • Advertise |
  • Let’s Talk

MyCodeTips mycodetips-newlogocopy1

  • Home
  • Basics
  • DSA
  • MAD
  • Concept
  • Practice
  • Misc
    • Tips
    • QA’s
    • Misc
  • Course
Tips&Tricks, Quick Tips, Swift

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 🙂

Written by Ranjan - August 10, 2021 - 1176 Views
Tags | swift, Tips & Tricks
AUTHOR
Ranjan

This website is basically about of what we learnt from my years of experience as a software engineer on software development specifically on mobile application development, design patterns/architectures and its changing scenarios, security, troubleshooting, tools, tips&tricks and many more.

You Might Also Like

mycodetips-newlogo2

How to catch a Nan?

September 26, 2013
MyCodetips Featured apps guidelines

Limitation and restriction of designing mobile apps

May 13, 2023
swift-optionals

Optionals in Swift ( ! ? )

August 15, 2021
Next Post
Previous Post

Support us

  • Exploring Single Point Failures: Causes and Impacts
  • Exploring the Pros and Cons of Primitive Data Types
  • Essential Coding Standards and Best Practices for Clean Code
  • What Business Problems Solves in Low Level Design (LLD)
  • SRP : Single Responsibility Principle in Swift and Objective-C
whiteboard

Whiteboard(PRO)

whiteboard

Whiteboard(lite)

alphabets

Kids Alphabet

do2day

Do2Day

MyCodeTips

©mycodetips.com