• Home
  • Basics
  • DSA
  • MAD
  • Concept
  • Practice
  • Misc
  • Tips
  • QA’s
  • Home
  • Basics
  • DSA
  • MAD
  • Concept
  • Practice
  • Misc
  • Tips
  • QA’s
  • #News
  • #APPS
  • #Events
    • #WWDC
    • #I/O
    • #Ignite
  • #Let’s Talk
  • #Interview
  • #Tips

MyCodeTips mycodetips-newlogocopy1

  • Home
  • Basics
  • DSA
  • MAD
  • Concept
  • Practice
  • Misc
  • Tips
  • QA’s
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 🙂

Liked it? Take a second to support Ranjan on Patreon!
Become a patron at Patreon!
  • Click to share on Reddit (Opens in new window)
  • Click to share on Facebook (Opens in new window)
  • Click to share on Twitter (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)
  • Click to share on Tumblr (Opens in new window)
  • More
  • Click to share on Pocket (Opens in new window)
  • Click to share on Pinterest (Opens in new window)
Written by Ranjan - 982 Views
Tags | swift, Tips & Tricks
AUTHOR
Ranjan

Namaste, My name is Ranjan, I am a graduate from NIT Rourkela. This website is basically about of what i learnt from my years of experience as a software engineer on software development specifically on mobile application development, design patterns/architectures, its changing scenarios, security, troubleshooting, tools, tips&tricks and many more.

You Might Also Like

mycodetips-newlogo2

How to Use Your Computer Without a Mouse-Part-1

October 14, 2013
swift-concurrency-await

Concurrency in Swift

November 17, 2021
and-or-not-condition

Operators in Swift (AND, OR, or NOT.)

August 6, 2021
Next Post
Previous Post

Support us

Subscribe for updates

Join 8,220 other subscribers

Latest Posts

  • YT-Featured-Templates--lld
    What Business Problems Solves in Low Level Design (LLD)
  • SRP-SingleResopnsibility
    SRP : Single Responsibility Principle in Swift and Objective-C
  • Designing Mobile APPS
    Limitation and restriction of designing mobile apps
  • YT-Featured-solidprinciples
    SOLID Principles of Software Design
  • IOS 16 Features
    Latest features in IOS 16
whiteboard

Whiteboard(PRO)

whiteboard

Whiteboard(lite)

alphabets

Kids Alphabet

do2day

Do2Day

  • #about
  • #myapps
  • #contact
  • #privacy
  • #Advertise
  • #myQuestions

.Net Android Blogging Cloud Concept Database DSA ERROR ExcelTips Flutter Interview IOS IOSQuestions JAVA Javascript MAC-OS No-Mouse Objective-c Programming Quick Tips SEO Software Design & Architecture Swift SwiftUI Tips&Tricks Tools Troubleshoot Videos Web Wordpress Xamarin XCode

  • What Business Problems Solves in Low Level Design (LLD)
  • SRP : Single Responsibility Principle in Swift and Objective-C
  • Limitation and restriction of designing mobile apps
  • SOLID Principles of Software Design
  • Latest features in IOS 16
MyCodeTips

©mycodetips.com