SlideShare a Scribd company logo
Swift Study Group
Basic Operator, String
and Characters
2015/8/11
Joe
Outline
• Basic Operators
• Strings and Characters
Basic Operators
Kind of Operators
• Unary: -a, !b, i++
• Binary: 2+3
• Ternary: a ? b : c
Assignment Operator
• let a = 1
• let (a,b) = (1,2)
• if x = y { } : the behavior of assigning value will
not return value
Arithmetic Operators
• +: It is also supported for String concatenation.
• %: It is also operate on floating-point numbers
• Question:
• -8 % 3
• 5 / -2
• 8 % 2.5
Increment and Decrement
Operators
• If the operator is written before the variable, it
increments the variable before returning its
value.
• ++i
• If the operator is written after the variable, it
increments the variable after returning its value.
• i++
Increment and Decrement
Operators
var i = 1
i++
i
i = 1
++i
i
Others
• Unary Minus Operator: -3
• Unary Plus Operator: +3
• Compound Assignment Operators: a += 2
• Ternary conditional operator: hasHeader ? 2 : 3
• Logical Operator: NOT(!), AND(&&), OR(||)
Comparison Operators
• a === b
• a != b
• a > b
• a < b
• a >= b
• a <= b
• a === b
let a = NSObject()
let b = NSObject()
let c = a
a === b
a === c
How about string comparison ?
Nil Coalescing Operator
• The nil coalescing operator (a ?? b) unwraps an
optional if it contains a value, or returns a default
value b if a is nil.
• (a != nil) ? a! : b
Range Operators
• Closed Range Operator: 1…5
• Half-Open Range Operator: 1..<5
Strings and Characters
Composition of String
• String -> Character -> extended grapheme
cluster -> Unicode scalar
String
• Literal: “ ”
• Empty String: a = “”, a = String(), a.isEmpty
• Mutability: var s = “Hello” s+=“World”
• Strings are value types not reference types.
• Concatenating with Character: 

let exclamationMark: Character = “!”

s += exclamationMark
Characters
• String type represents a collection of Character
value in a specified order.
• String value can be constructed by passing an
array of Character values as an argument to its
initializer
String Interpolation
• String interpolation is a way to construct a new
String value from a mix of constants, variables,
literals and expressions by including their values
inside a string literal.
• let multiplier = 3

let message = “(multiplier) times 2.5 is 
(Double(multiplier) * 2.5)”
Unicode
• Unicode is an international standard for
encoding, representing, and processing text in
different writing systems.
Unicode Scalars
• A Unicode scalar is a unique 21-bit number for
character or modifier, such as U+0061 for “a”

U+1F425 for
Special Character in String
Literal (1/2)
• Special Characters
• 0 null character
•  backslash
• t horizontal tab
• n line feed
• r carriage return
• ” double quote
• ’ single quote
let message = ""Hello World""
Special Character in String
Literal (2/2)
• An arbitrary Unicode scalar, written as u{n},
where n is 1-8 digit hexadecimal number with a
value equal to a valid Unicode code point.
var str = "u{1F425}"
Extended Grapheme
Clusters(1/2)
• Every instance of Swift’s Character type
represents a single extended grapheme cluster.
• An extended grapheme cluster is a sequence of
one or more Unicode scalars that produce a
single human-readable character.
Extended Grapheme
Clusters(2/2)
is composed of one or two Unicode Scalars
which is a single extended grapheme cluster
is composed of one or three Unicode Scalars
which is a single extended grapheme cluster
Counting Characters
var word = "cafe"
count(word)
word += "u{301}"
count(word)
Accessing and Modifying a
String
• Swift strings cannot be indexed by integer
values.
• Using String index instead.Type: String.Index
String.Index
• startIndex
• endIndex
• startIndex.successor()
• endIndex.predecessor()
• indices
Inserting and Removing
• insert(_:atIndex) : To insert a character into a
string at a specified index.
• splice(_:atIndex) : To insert another string at a
specified index.
• removeAtIndex(_:atIndex): To remove a character
from a string at a specified index.
• removeRange(_:range): To remove a substring at
a specified range.
String and Character
Equality
• ==, !=
• Two string values are considered equal if their
extended grapheme clusters are canonically
equivalent if they have the same linguistic
meaning and appearance.
Prefix and Suffix Equality
• hasPrefix(_:)
• hasSuffix(_:)
Unicode Representation of
Strings
• When a Unicode string is written to a text file or
some other storage, the Unicode scalars in that
string are encoded in one of several Unicode-
defined encoding forms.
• UTF-8
• UTF-16
• Unicode Scalar
Reference
• The Swift Programming Language
• https://gist.github.com/joehsieh/
5dffe9a5e49421c8cde5

More Related Content

What's hot

How to execute a C program
How to execute a C  program How to execute a C  program
How to execute a C program
Leela Koneru
 
JAVA PROGRAMMING
JAVA PROGRAMMING JAVA PROGRAMMING
JAVA PROGRAMMING
Niyitegekabilly
 
Strings in c++
Strings in c++Strings in c++
Strings in c++
Neeru Mittal
 
Introduction Of C++
Introduction Of C++Introduction Of C++
Introduction Of C++
Sangharsh agarwal
 
Object-oriented concepts
Object-oriented conceptsObject-oriented concepts
Object-oriented concepts
BG Java EE Course
 
JavaScript Data Types
JavaScript Data TypesJavaScript Data Types
JavaScript Data Types
Charles Russell
 
2. HTML forms
2. HTML forms2. HTML forms
2. HTML forms
Pavle Đorđević
 
Programming in c
Programming in cProgramming in c
Programming in c
vineet4523
 
1 D Arrays in C++
1 D Arrays in C++1 D Arrays in C++
1 D Arrays in C++
poonam.rwalia
 
Enumerated data types in C
Enumerated data types in CEnumerated data types in C
Enumerated data types in C
Arpana shree
 
Css selectors
Css selectorsCss selectors
Css selectors
Parth Trivedi
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
03062679929
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
Andres Baravalle
 
Unit 3. Input and Output
Unit 3. Input and OutputUnit 3. Input and Output
Unit 3. Input and Output
Ashim Lamichhane
 
C++ Overview
C++ OverviewC++ Overview
C++ Overview
kelleyc3
 
Structure in C
Structure in CStructure in C
Structure in C
Kamal Acharya
 
Dynamic Memory Allocation(DMA)
Dynamic Memory Allocation(DMA)Dynamic Memory Allocation(DMA)
Dynamic Memory Allocation(DMA)
Kamal Acharya
 
Introduction to object oriented programming
Introduction to object oriented programmingIntroduction to object oriented programming
Introduction to object oriented programming
Abzetdin Adamov
 
Operators in python
Operators in pythonOperators in python
Operators in python
eShikshak
 
Strings in c
Strings in cStrings in c
Strings in c
vampugani
 

What's hot (20)

How to execute a C program
How to execute a C  program How to execute a C  program
How to execute a C program
 
JAVA PROGRAMMING
JAVA PROGRAMMING JAVA PROGRAMMING
JAVA PROGRAMMING
 
Strings in c++
Strings in c++Strings in c++
Strings in c++
 
Introduction Of C++
Introduction Of C++Introduction Of C++
Introduction Of C++
 
Object-oriented concepts
Object-oriented conceptsObject-oriented concepts
Object-oriented concepts
 
JavaScript Data Types
JavaScript Data TypesJavaScript Data Types
JavaScript Data Types
 
2. HTML forms
2. HTML forms2. HTML forms
2. HTML forms
 
Programming in c
Programming in cProgramming in c
Programming in c
 
1 D Arrays in C++
1 D Arrays in C++1 D Arrays in C++
1 D Arrays in C++
 
Enumerated data types in C
Enumerated data types in CEnumerated data types in C
Enumerated data types in C
 
Css selectors
Css selectorsCss selectors
Css selectors
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
Unit 3. Input and Output
Unit 3. Input and OutputUnit 3. Input and Output
Unit 3. Input and Output
 
C++ Overview
C++ OverviewC++ Overview
C++ Overview
 
Structure in C
Structure in CStructure in C
Structure in C
 
Dynamic Memory Allocation(DMA)
Dynamic Memory Allocation(DMA)Dynamic Memory Allocation(DMA)
Dynamic Memory Allocation(DMA)
 
Introduction to object oriented programming
Introduction to object oriented programmingIntroduction to object oriented programming
Introduction to object oriented programming
 
Operators in python
Operators in pythonOperators in python
Operators in python
 
Strings in c
Strings in cStrings in c
Strings in c
 

Viewers also liked

Leadership Circle Profile - The Leadership Circle Profile Increases Leader Ca...
Leadership Circle Profile - The Leadership Circle Profile Increases Leader Ca...Leadership Circle Profile - The Leadership Circle Profile Increases Leader Ca...
Leadership Circle Profile - The Leadership Circle Profile Increases Leader Ca...
818 Group
 
Job detail (2)
Job detail (2)Job detail (2)
Job detail (2)
Donna Ariñas
 
Java Instantiation
Java InstantiationJava Instantiation
Java Instantiation
Shahid Rasheed
 
Java Variable Types
Java Variable TypesJava Variable Types
Java Variable Types
Shahid Rasheed
 
Vouloir présent
Vouloir présentVouloir présent
Vouloir présentMansour1
 
Tong hop diem cac huyen năm 2016
Tong hop diem cac huyen năm 2016Tong hop diem cac huyen năm 2016
Tong hop diem cac huyen năm 2016
fomicotung
 
Gatopardo Ecuador Abril 2013
Gatopardo Ecuador Abril 2013Gatopardo Ecuador Abril 2013
Gatopardo Ecuador Abril 2013
Cristina Izurieta Moreno
 
9. cv góp ý nđ nđ về kinh doanh mũ bảo hiểm
9. cv góp ý nđ nđ về kinh doanh mũ bảo hiểm9. cv góp ý nđ nđ về kinh doanh mũ bảo hiểm
9. cv góp ý nđ nđ về kinh doanh mũ bảo hiểm
Là Nắng Anh
 
Arithmetic operator
Arithmetic operatorArithmetic operator
Arithmetic operator
Md Masudur Rahman
 
Gatopardo Ecuador marzo 2013
Gatopardo Ecuador marzo 2013Gatopardo Ecuador marzo 2013
Gatopardo Ecuador marzo 2013
Cristina Izurieta Moreno
 
Mi música Sandra Sóstenes
Mi música Sandra SóstenesMi música Sandra Sóstenes
Mi música Sandra Sóstenes
Sann Sóstenes
 
Viburnix
Viburnix Viburnix
Manual de Carreño - Urbanidad y Buenas Maneras
Manual de Carreño - Urbanidad y Buenas ManerasManual de Carreño - Urbanidad y Buenas Maneras
Manual de Carreño - Urbanidad y Buenas Maneras
Jairo Sandoval H
 
Wave propagation properties
Wave propagation propertiesWave propagation properties
Wave propagation properties
Izah Asmadi
 
Global Alumni Management
Global Alumni ManagementGlobal Alumni Management
Global Alumni Management
Tian Qin
 
Acero y vidrio.
Acero y vidrio.Acero y vidrio.
Acero y vidrio.
Gabriel Buda
 
fading channels
 fading channels fading channels
fading channels
Faisal Farooq
 
ODPi 101: Who we are, What we do
ODPi 101: Who we are, What we doODPi 101: Who we are, What we do
ODPi 101: Who we are, What we do
Hortonworks
 
DANH SÁCH KHÁCH HÀNG MIỄN PHÍ
DANH SÁCH KHÁCH HÀNG MIỄN PHÍDANH SÁCH KHÁCH HÀNG MIỄN PHÍ
DANH SÁCH KHÁCH HÀNG MIỄN PHÍ
thongtinkhachhang
 
BeautyNow Pitch Deck
BeautyNow Pitch DeckBeautyNow Pitch Deck
BeautyNow Pitch Deck
Aleberry Creative, LLC
 

Viewers also liked (20)

Leadership Circle Profile - The Leadership Circle Profile Increases Leader Ca...
Leadership Circle Profile - The Leadership Circle Profile Increases Leader Ca...Leadership Circle Profile - The Leadership Circle Profile Increases Leader Ca...
Leadership Circle Profile - The Leadership Circle Profile Increases Leader Ca...
 
Job detail (2)
Job detail (2)Job detail (2)
Job detail (2)
 
Java Instantiation
Java InstantiationJava Instantiation
Java Instantiation
 
Java Variable Types
Java Variable TypesJava Variable Types
Java Variable Types
 
Vouloir présent
Vouloir présentVouloir présent
Vouloir présent
 
Tong hop diem cac huyen năm 2016
Tong hop diem cac huyen năm 2016Tong hop diem cac huyen năm 2016
Tong hop diem cac huyen năm 2016
 
Gatopardo Ecuador Abril 2013
Gatopardo Ecuador Abril 2013Gatopardo Ecuador Abril 2013
Gatopardo Ecuador Abril 2013
 
9. cv góp ý nđ nđ về kinh doanh mũ bảo hiểm
9. cv góp ý nđ nđ về kinh doanh mũ bảo hiểm9. cv góp ý nđ nđ về kinh doanh mũ bảo hiểm
9. cv góp ý nđ nđ về kinh doanh mũ bảo hiểm
 
Arithmetic operator
Arithmetic operatorArithmetic operator
Arithmetic operator
 
Gatopardo Ecuador marzo 2013
Gatopardo Ecuador marzo 2013Gatopardo Ecuador marzo 2013
Gatopardo Ecuador marzo 2013
 
Mi música Sandra Sóstenes
Mi música Sandra SóstenesMi música Sandra Sóstenes
Mi música Sandra Sóstenes
 
Viburnix
Viburnix Viburnix
Viburnix
 
Manual de Carreño - Urbanidad y Buenas Maneras
Manual de Carreño - Urbanidad y Buenas ManerasManual de Carreño - Urbanidad y Buenas Maneras
Manual de Carreño - Urbanidad y Buenas Maneras
 
Wave propagation properties
Wave propagation propertiesWave propagation properties
Wave propagation properties
 
Global Alumni Management
Global Alumni ManagementGlobal Alumni Management
Global Alumni Management
 
Acero y vidrio.
Acero y vidrio.Acero y vidrio.
Acero y vidrio.
 
fading channels
 fading channels fading channels
fading channels
 
ODPi 101: Who we are, What we do
ODPi 101: Who we are, What we doODPi 101: Who we are, What we do
ODPi 101: Who we are, What we do
 
DANH SÁCH KHÁCH HÀNG MIỄN PHÍ
DANH SÁCH KHÁCH HÀNG MIỄN PHÍDANH SÁCH KHÁCH HÀNG MIỄN PHÍ
DANH SÁCH KHÁCH HÀNG MIỄN PHÍ
 
BeautyNow Pitch Deck
BeautyNow Pitch DeckBeautyNow Pitch Deck
BeautyNow Pitch Deck
 

Similar to Basic Operator, String and Characters in Swift.

Javascript
JavascriptJavascript
Javascript
Sunil Thakur
 
3 Datatypes
3 Datatypes3 Datatypes
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)
arvind pandey
 
Engineering CS 5th Sem Python Module -2.pptx
Engineering CS 5th Sem Python Module -2.pptxEngineering CS 5th Sem Python Module -2.pptx
Engineering CS 5th Sem Python Module -2.pptx
hardii0991
 
Chapter 2 java
Chapter 2 javaChapter 2 java
Chapter 2 java
ahmed abugharsa
 
R Programing language Notes Unit 5 Data Viz in R
R Programing language Notes Unit 5 Data Viz in RR Programing language Notes Unit 5 Data Viz in R
R Programing language Notes Unit 5 Data Viz in R
en20cs301479
 
C Session 2.pptx for engninering students
C Session 2.pptx for engninering studentsC Session 2.pptx for engninering students
C Session 2.pptx for engninering students
nraj02252
 
Python Basics.pptx
Python Basics.pptxPython Basics.pptx
Python Basics.pptx
16115yogendraSingh
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
Ayshwarya Baburam
 
JavaScript.pptx
JavaScript.pptxJavaScript.pptx
JavaScript.pptx
KennyPratheepKumar
 
Scala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryScala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud Foundry
Pray Desai
 
Preparing Java 7 Certifications
Preparing Java 7 CertificationsPreparing Java 7 Certifications
Preparing Java 7 Certifications
Giacomo Veneri
 
Python Programming | JNTUK | UNIT 1 | Lecture 4
Python Programming | JNTUK | UNIT 1 | Lecture 4Python Programming | JNTUK | UNIT 1 | Lecture 4
Python Programming | JNTUK | UNIT 1 | Lecture 4
FabMinds
 
Should i Go there
Should i Go thereShould i Go there
Should i Go there
Shimi Bandiel
 
kotlin-nutshell.pptx
kotlin-nutshell.pptxkotlin-nutshell.pptx
kotlin-nutshell.pptx
AbdulRazaqAnjum
 
Chapter 2: Elementary Programming
Chapter 2: Elementary ProgrammingChapter 2: Elementary Programming
Chapter 2: Elementary Programming
Eric Chou
 
Swift Study #3
Swift Study #3Swift Study #3
Swift Study #3
chanju Jeon
 
unit1 python.pptx
unit1 python.pptxunit1 python.pptx
unit1 python.pptx
TKSanthoshRao
 
Net framework
Net frameworkNet framework
Net framework
Abhishek Mukherjee
 
Functional programming with F#
Functional programming with F#Functional programming with F#
Functional programming with F#
Remik Koczapski
 

Similar to Basic Operator, String and Characters in Swift. (20)

Javascript
JavascriptJavascript
Javascript
 
3 Datatypes
3 Datatypes3 Datatypes
3 Datatypes
 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)
 
Engineering CS 5th Sem Python Module -2.pptx
Engineering CS 5th Sem Python Module -2.pptxEngineering CS 5th Sem Python Module -2.pptx
Engineering CS 5th Sem Python Module -2.pptx
 
Chapter 2 java
Chapter 2 javaChapter 2 java
Chapter 2 java
 
R Programing language Notes Unit 5 Data Viz in R
R Programing language Notes Unit 5 Data Viz in RR Programing language Notes Unit 5 Data Viz in R
R Programing language Notes Unit 5 Data Viz in R
 
C Session 2.pptx for engninering students
C Session 2.pptx for engninering studentsC Session 2.pptx for engninering students
C Session 2.pptx for engninering students
 
Python Basics.pptx
Python Basics.pptxPython Basics.pptx
Python Basics.pptx
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
JavaScript.pptx
JavaScript.pptxJavaScript.pptx
JavaScript.pptx
 
Scala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryScala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud Foundry
 
Preparing Java 7 Certifications
Preparing Java 7 CertificationsPreparing Java 7 Certifications
Preparing Java 7 Certifications
 
Python Programming | JNTUK | UNIT 1 | Lecture 4
Python Programming | JNTUK | UNIT 1 | Lecture 4Python Programming | JNTUK | UNIT 1 | Lecture 4
Python Programming | JNTUK | UNIT 1 | Lecture 4
 
Should i Go there
Should i Go thereShould i Go there
Should i Go there
 
kotlin-nutshell.pptx
kotlin-nutshell.pptxkotlin-nutshell.pptx
kotlin-nutshell.pptx
 
Chapter 2: Elementary Programming
Chapter 2: Elementary ProgrammingChapter 2: Elementary Programming
Chapter 2: Elementary Programming
 
Swift Study #3
Swift Study #3Swift Study #3
Swift Study #3
 
unit1 python.pptx
unit1 python.pptxunit1 python.pptx
unit1 python.pptx
 
Net framework
Net frameworkNet framework
Net framework
 
Functional programming with F#
Functional programming with F#Functional programming with F#
Functional programming with F#
 

Recently uploaded

Going AOT: Everything you need to know about GraalVM for Java applications
Going AOT: Everything you need to know about GraalVM for Java applicationsGoing AOT: Everything you need to know about GraalVM for Java applications
Going AOT: Everything you need to know about GraalVM for Java applications
Alina Yurenko
 
The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...
The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...
The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...
kalichargn70th171
 
Folding Cheat Sheet #5 - fifth in a series
Folding Cheat Sheet #5 - fifth in a seriesFolding Cheat Sheet #5 - fifth in a series
Folding Cheat Sheet #5 - fifth in a series
Philip Schwarz
 
Call Girls Bangalore🔥7023059433🔥Best Profile Escorts in Bangalore Available 24/7
Call Girls Bangalore🔥7023059433🔥Best Profile Escorts in Bangalore Available 24/7Call Girls Bangalore🔥7023059433🔥Best Profile Escorts in Bangalore Available 24/7
Call Girls Bangalore🔥7023059433🔥Best Profile Escorts in Bangalore Available 24/7
manji sharman06
 
What’s new in VictoriaMetrics - Q2 2024 Update
What’s new in VictoriaMetrics - Q2 2024 UpdateWhat’s new in VictoriaMetrics - Q2 2024 Update
What’s new in VictoriaMetrics - Q2 2024 Update
VictoriaMetrics
 
美洲杯赔率投注网【​网址​🎉3977·EE​🎉】
美洲杯赔率投注网【​网址​🎉3977·EE​🎉】美洲杯赔率投注网【​网址​🎉3977·EE​🎉】
美洲杯赔率投注网【​网址​🎉3977·EE​🎉】
widenerjobeyrl638
 
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptxMigration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
ervikas4
 
🏎️Tech Transformation: DevOps Insights from the Experts 👩‍💻
🏎️Tech Transformation: DevOps Insights from the Experts 👩‍💻🏎️Tech Transformation: DevOps Insights from the Experts 👩‍💻
🏎️Tech Transformation: DevOps Insights from the Experts 👩‍💻
campbellclarkson
 
Hands-on with Apache Druid: Installation & Data Ingestion Steps
Hands-on with Apache Druid: Installation & Data Ingestion StepsHands-on with Apache Druid: Installation & Data Ingestion Steps
Hands-on with Apache Druid: Installation & Data Ingestion Steps
servicesNitor
 
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
The Third Creative Media
 
What’s New in VictoriaLogs - Q2 2024 Update
What’s New in VictoriaLogs - Q2 2024 UpdateWhat’s New in VictoriaLogs - Q2 2024 Update
What’s New in VictoriaLogs - Q2 2024 Update
VictoriaMetrics
 
Streamlining End-to-End Testing Automation
Streamlining End-to-End Testing AutomationStreamlining End-to-End Testing Automation
Streamlining End-to-End Testing Automation
Anand Bagmar
 
Strengthening Web Development with CommandBox 6: Seamless Transition and Scal...
Strengthening Web Development with CommandBox 6: Seamless Transition and Scal...Strengthening Web Development with CommandBox 6: Seamless Transition and Scal...
Strengthening Web Development with CommandBox 6: Seamless Transition and Scal...
Ortus Solutions, Corp
 
Secure-by-Design Using Hardware and Software Protection for FDA Compliance
Secure-by-Design Using Hardware and Software Protection for FDA ComplianceSecure-by-Design Using Hardware and Software Protection for FDA Compliance
Secure-by-Design Using Hardware and Software Protection for FDA Compliance
ICS
 
Operational ease MuleSoft and Salesforce Service Cloud Solution v1.0.pptx
Operational ease MuleSoft and Salesforce Service Cloud Solution v1.0.pptxOperational ease MuleSoft and Salesforce Service Cloud Solution v1.0.pptx
Operational ease MuleSoft and Salesforce Service Cloud Solution v1.0.pptx
sandeepmenon62
 
Beginner's Guide to Observability@Devoxx PL 2024
Beginner's  Guide to Observability@Devoxx PL 2024Beginner's  Guide to Observability@Devoxx PL 2024
Beginner's Guide to Observability@Devoxx PL 2024
michniczscribd
 
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSISDECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
Tier1 app
 
42 Ways to Generate Real Estate Leads - Sellxpert
42 Ways to Generate Real Estate Leads - Sellxpert42 Ways to Generate Real Estate Leads - Sellxpert
42 Ways to Generate Real Estate Leads - Sellxpert
vaishalijagtap12
 
Cost-Effective Strategies For iOS App Development
Cost-Effective Strategies For iOS App DevelopmentCost-Effective Strategies For iOS App Development
Cost-Effective Strategies For iOS App Development
Softradix Technologies
 

Recently uploaded (20)

Going AOT: Everything you need to know about GraalVM for Java applications
Going AOT: Everything you need to know about GraalVM for Java applicationsGoing AOT: Everything you need to know about GraalVM for Java applications
Going AOT: Everything you need to know about GraalVM for Java applications
 
The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...
The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...
The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...
 
Folding Cheat Sheet #5 - fifth in a series
Folding Cheat Sheet #5 - fifth in a seriesFolding Cheat Sheet #5 - fifth in a series
Folding Cheat Sheet #5 - fifth in a series
 
Call Girls Bangalore🔥7023059433🔥Best Profile Escorts in Bangalore Available 24/7
Call Girls Bangalore🔥7023059433🔥Best Profile Escorts in Bangalore Available 24/7Call Girls Bangalore🔥7023059433🔥Best Profile Escorts in Bangalore Available 24/7
Call Girls Bangalore🔥7023059433🔥Best Profile Escorts in Bangalore Available 24/7
 
What’s new in VictoriaMetrics - Q2 2024 Update
What’s new in VictoriaMetrics - Q2 2024 UpdateWhat’s new in VictoriaMetrics - Q2 2024 Update
What’s new in VictoriaMetrics - Q2 2024 Update
 
bgiolcb
bgiolcbbgiolcb
bgiolcb
 
美洲杯赔率投注网【​网址​🎉3977·EE​🎉】
美洲杯赔率投注网【​网址​🎉3977·EE​🎉】美洲杯赔率投注网【​网址​🎉3977·EE​🎉】
美洲杯赔率投注网【​网址​🎉3977·EE​🎉】
 
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptxMigration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
 
🏎️Tech Transformation: DevOps Insights from the Experts 👩‍💻
🏎️Tech Transformation: DevOps Insights from the Experts 👩‍💻🏎️Tech Transformation: DevOps Insights from the Experts 👩‍💻
🏎️Tech Transformation: DevOps Insights from the Experts 👩‍💻
 
Hands-on with Apache Druid: Installation & Data Ingestion Steps
Hands-on with Apache Druid: Installation & Data Ingestion StepsHands-on with Apache Druid: Installation & Data Ingestion Steps
Hands-on with Apache Druid: Installation & Data Ingestion Steps
 
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
 
What’s New in VictoriaLogs - Q2 2024 Update
What’s New in VictoriaLogs - Q2 2024 UpdateWhat’s New in VictoriaLogs - Q2 2024 Update
What’s New in VictoriaLogs - Q2 2024 Update
 
Streamlining End-to-End Testing Automation
Streamlining End-to-End Testing AutomationStreamlining End-to-End Testing Automation
Streamlining End-to-End Testing Automation
 
Strengthening Web Development with CommandBox 6: Seamless Transition and Scal...
Strengthening Web Development with CommandBox 6: Seamless Transition and Scal...Strengthening Web Development with CommandBox 6: Seamless Transition and Scal...
Strengthening Web Development with CommandBox 6: Seamless Transition and Scal...
 
Secure-by-Design Using Hardware and Software Protection for FDA Compliance
Secure-by-Design Using Hardware and Software Protection for FDA ComplianceSecure-by-Design Using Hardware and Software Protection for FDA Compliance
Secure-by-Design Using Hardware and Software Protection for FDA Compliance
 
Operational ease MuleSoft and Salesforce Service Cloud Solution v1.0.pptx
Operational ease MuleSoft and Salesforce Service Cloud Solution v1.0.pptxOperational ease MuleSoft and Salesforce Service Cloud Solution v1.0.pptx
Operational ease MuleSoft and Salesforce Service Cloud Solution v1.0.pptx
 
Beginner's Guide to Observability@Devoxx PL 2024
Beginner's  Guide to Observability@Devoxx PL 2024Beginner's  Guide to Observability@Devoxx PL 2024
Beginner's Guide to Observability@Devoxx PL 2024
 
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSISDECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
 
42 Ways to Generate Real Estate Leads - Sellxpert
42 Ways to Generate Real Estate Leads - Sellxpert42 Ways to Generate Real Estate Leads - Sellxpert
42 Ways to Generate Real Estate Leads - Sellxpert
 
Cost-Effective Strategies For iOS App Development
Cost-Effective Strategies For iOS App DevelopmentCost-Effective Strategies For iOS App Development
Cost-Effective Strategies For iOS App Development
 

Basic Operator, String and Characters in Swift.

  • 1. Swift Study Group Basic Operator, String and Characters 2015/8/11 Joe
  • 2. Outline • Basic Operators • Strings and Characters
  • 4. Kind of Operators • Unary: -a, !b, i++ • Binary: 2+3 • Ternary: a ? b : c
  • 5. Assignment Operator • let a = 1 • let (a,b) = (1,2) • if x = y { } : the behavior of assigning value will not return value
  • 6. Arithmetic Operators • +: It is also supported for String concatenation. • %: It is also operate on floating-point numbers • Question: • -8 % 3 • 5 / -2 • 8 % 2.5
  • 7. Increment and Decrement Operators • If the operator is written before the variable, it increments the variable before returning its value. • ++i • If the operator is written after the variable, it increments the variable after returning its value. • i++
  • 8. Increment and Decrement Operators var i = 1 i++ i i = 1 ++i i
  • 9. Others • Unary Minus Operator: -3 • Unary Plus Operator: +3 • Compound Assignment Operators: a += 2 • Ternary conditional operator: hasHeader ? 2 : 3 • Logical Operator: NOT(!), AND(&&), OR(||)
  • 10. Comparison Operators • a === b • a != b • a > b • a < b • a >= b • a <= b • a === b let a = NSObject() let b = NSObject() let c = a a === b a === c How about string comparison ?
  • 11. Nil Coalescing Operator • The nil coalescing operator (a ?? b) unwraps an optional if it contains a value, or returns a default value b if a is nil. • (a != nil) ? a! : b
  • 12. Range Operators • Closed Range Operator: 1…5 • Half-Open Range Operator: 1..<5
  • 14. Composition of String • String -> Character -> extended grapheme cluster -> Unicode scalar
  • 15. String • Literal: “ ” • Empty String: a = “”, a = String(), a.isEmpty • Mutability: var s = “Hello” s+=“World” • Strings are value types not reference types. • Concatenating with Character: 
 let exclamationMark: Character = “!”
 s += exclamationMark
  • 16. Characters • String type represents a collection of Character value in a specified order. • String value can be constructed by passing an array of Character values as an argument to its initializer
  • 17. String Interpolation • String interpolation is a way to construct a new String value from a mix of constants, variables, literals and expressions by including their values inside a string literal. • let multiplier = 3
 let message = “(multiplier) times 2.5 is (Double(multiplier) * 2.5)”
  • 18. Unicode • Unicode is an international standard for encoding, representing, and processing text in different writing systems.
  • 19. Unicode Scalars • A Unicode scalar is a unique 21-bit number for character or modifier, such as U+0061 for “a”
 U+1F425 for
  • 20. Special Character in String Literal (1/2) • Special Characters • 0 null character • backslash • t horizontal tab • n line feed • r carriage return • ” double quote • ’ single quote let message = ""Hello World""
  • 21. Special Character in String Literal (2/2) • An arbitrary Unicode scalar, written as u{n}, where n is 1-8 digit hexadecimal number with a value equal to a valid Unicode code point. var str = "u{1F425}"
  • 22. Extended Grapheme Clusters(1/2) • Every instance of Swift’s Character type represents a single extended grapheme cluster. • An extended grapheme cluster is a sequence of one or more Unicode scalars that produce a single human-readable character.
  • 23. Extended Grapheme Clusters(2/2) is composed of one or two Unicode Scalars which is a single extended grapheme cluster is composed of one or three Unicode Scalars which is a single extended grapheme cluster
  • 24. Counting Characters var word = "cafe" count(word) word += "u{301}" count(word)
  • 25. Accessing and Modifying a String • Swift strings cannot be indexed by integer values. • Using String index instead.Type: String.Index
  • 26. String.Index • startIndex • endIndex • startIndex.successor() • endIndex.predecessor() • indices
  • 27. Inserting and Removing • insert(_:atIndex) : To insert a character into a string at a specified index. • splice(_:atIndex) : To insert another string at a specified index. • removeAtIndex(_:atIndex): To remove a character from a string at a specified index. • removeRange(_:range): To remove a substring at a specified range.
  • 28. String and Character Equality • ==, != • Two string values are considered equal if their extended grapheme clusters are canonically equivalent if they have the same linguistic meaning and appearance.
  • 29. Prefix and Suffix Equality • hasPrefix(_:) • hasSuffix(_:)
  • 30. Unicode Representation of Strings • When a Unicode string is written to a text file or some other storage, the Unicode scalars in that string are encoded in one of several Unicode- defined encoding forms. • UTF-8 • UTF-16 • Unicode Scalar
  • 31. Reference • The Swift Programming Language • https://gist.github.com/joehsieh/ 5dffe9a5e49421c8cde5