SlideShare a Scribd company logo
iOS App Development Certification Training www.edureka.co/ios-development
iOS App Development Certification Training www.edureka.co/ios-development
Topics For Today’s Session
What is Swift?
Xcode IDE
Swift Fundamentals
iOS App Development Certification Training www.edureka.co/ios-development
What is Swift?
❑ Swift is a programming language developed by Apple Inc for iOS and OS X
development.
❑ Swift adopts the best of C and Objective-C, without the constraints of C
compatibility.
❑ Swift uses the same runtime as the existing Objective-C system on Mac OS and
iOS, which enables programs to run on many existing iOS 6 and OS X 10.8
platforms.
iOS App Development Certification Training www.edureka.co/ios-development
Xcode IDE
❑ Xcode is an IDE for macOS , which contains a suite of
software development tools developed by Apple.
❑ This set of tools developed are used for developing
software for macOS, iOS, watchOS, and tvOS.
iOS App Development Certification Training www.edureka.co/ios-development
BASIC SYNTAX
White Spaces
Semicolons Literals
Identifiers
Tokens Keywords
Comments
iOS App Development Certification Training www.edureka.co/ios-development
Swift Basic Syntax
print("test!")
The individual tokens are:
print("test!")
White Spaces
Semicolons
Literals
Identifiers
Tokens
Keywords
Comments
❑ A Swift program can consists of various number of tokens.
❑ A token is either a keyword, an identifier, a constant, a string
literal, or a symbol.
Example:
iOS App Development Certification Training www.edureka.co/ios-development
Swift Basic Syntax
White Spaces
Semicolons
Literals
Identifiers
Tokens
Keywords
Comments
// This is the syntax for single-line comments.
/* This is the syntax for multi-line comments. */
/* This is the syntax for nested
/* multi-line comments. */ */
❑ Comments are like helping texts in a Swift program which are
ignored by the compiler.
❑ Multi-line comments start with /* and terminate with the
characters */ where as Single-line comments are written using //
at the beginning of the comment.
Example:
iOS App Development Certification Training www.edureka.co/ios-development
Swift Basic Syntax
White Spaces
Semicolons
Literals
Identifiers
Tokens
Keywords
Comments
❑ Swift does not require you to type a semicolon (;) after each
statement in the code.
❑ If you use multiple statements in the same line, then semicolon is
used as a delimiter.
/* Using two statements in the same line*/
var myString = "Hello, World!";print(myString)
Example:
iOS App Development Certification Training www.edureka.co/ios-development
Swift Basic Syntax
White Spaces
Semicolons
Literals
Identifiers
Tokens
Keywords
Comments
❑ An identifier starts with an alphabet A to Z or a to z or an
underscore _ followed by zero or more letters, underscores, and
digits (0 to 9).
❑ Swift is a case-sensitive language does not allow special
characters such as @, $, and % within identifiers.
Example:
Sahiti kappagantula xyz emp_name a_123
hello10 _abc y d12e8 returnVal _123_abc
iOS App Development Certification Training www.edureka.co/ios-development
Swift Basic Syntax
White Spaces
Semicolons
Literals
Identifiers
Tokens
Keywords
Comments
Keywords are reserved words which may not be used as constants or
variables or any other identifier names, unless they're escaped with
backticks.
Keywords Used In Declarations
Class deinit Enum extension Func
Let import Init internal public
typealias operator private protocol var
subscript static struct subscript
Keywords Used In Statements
break case continue default do
if else fallthrough for where
while in return switch
Keywords Used In Expressions And Types
as dynamicType false is true
nil self Self super _FUNCTION_
_LINE_ _COLUMN_ _FILE_
Keywords Used In Particular Contexts
associativity convenience dynamic didSet precedence
final get infix inout prefix
lazy left mutating none Protocol
nonmutating optional override postfix required
right set Type unowned weak
iOS App Development Certification Training www.edureka.co/ios-development
Swift Basic Syntax
White Spaces
Semicolons
Literals
Identifiers
Tokens
Keywords
Comments
❑ Whitespace is the term used in Swift to describe blanks, tabs,
newline characters, and comments.
❑ Whitespaces separate one part of a statement from another and
enable the compiler to identify where one element in a statement,
ends and the next element begins.
int age = a + b //Correct Statement
int age = a +b //Incorrect Statement
Example:
iOS App Development Certification Training www.edureka.co/ios-development
Swift Basic Syntax
White Spaces
Semicolons
Literals
Identifiers
Tokens
Keywords
Comments
❑ A literal is the source code representation of a value of an integer,
floating-point number, or string type.
72 // Integer literal
8.14659 // Floating-point literal
Hello, World!" // String literal
Example:
Integer Literal Floating Literals String Literals Boolean Literals
iOS App Development Certification Training www.edureka.co/ios-development
VARIABLES,
DATATYPES &
TYPE CASTING
iOS App Development Certification Training www.edureka.co/ios-development
VARIABLES
❑ A variable provides us with named storage that our programs can manipulate.
❑ Each variable in Swift has a specific type, which determines the size and layout of the
variable's memory.
var variableName = <initial value>
//We can also mention Type Annotations
var variableName:<data type> = <optional initial value>
Syntax:
iOS App Development Certification Training www.edureka.co/ios-development
Data Types
The Built-In Data Types are Int or UInt, Float, Double, Bool, String, Character, Optional, and Tuples.
Type Typical Bit Width Typical Range
Int8 1byte -127 to 127
UInt8 1byte 0 to 255
Int32 4bytes -2147483648 to 2147483647
UInt32 4bytes 0 to 4294967295
Int64 8bytes
-9223372036854775808 to
9223372036854775807
UInt64 8bytes 0 to 18446744073709551615
Float 4bytes 1.2E-38 to 3.4E+38 (~6 digits)
Double 8bytes 2.3E-308 to 1.7E+308 (~15 digits)
iOS App Development Certification Training www.edureka.co/ios-development
Data Types
typealias newname = type
typealias Feet = Int
var distance: Feet = 500
print(distance)
Type Inference
var varA = 42
print(varA)
varB = 3.14159
print(varB)
Type Safety
var varX = 67
varX = “Hi There"
print(varX)
Type Aliases
main.swift:2:8: error: cannot assign value of
type 'String' to type 'Int' varX = “Hi There”
iOS App Development Certification Training www.edureka.co/ios-development
Type Casting
Type Casting in simple terms is converting one data type into another data type.
let a: Int = 5679
let b: Float = 2.9999
print(“This number is an Int now (Int(b))”)
print(“This number is a Float now (Float(a))”)
let myAge = “17.5” //Convert String To Integer & Float
let myAgeConvInt = myAge.toInt()
let myAgeConvFloat = (myAge as NSString).floatValue
Example:
iOS App Development Certification Training www.edureka.co/ios-development
OPERATORS
Arithmetic Comparison Logical Bitwise
Assignment Range Misc
iOS App Development Certification Training www.edureka.co/ios-development
Arithmetic Operators
Arithmetic
Comparison
Logical
Bitwise
Assignment
Range
Misc
+ - * / %
== != > < >= <=
&& || !
& | ^ ~ << >>
= += -= *= /= %= <<= >>= &= ^= !=
Closed Range Half-Open Range One-Sided Range
Unary Minus Unary Plus Ternary Conditional
iOS App Development Certification Training www.edureka.co/ios-development
CONDITIONAL
STATEMENTS
If
If-Else
Switch
iOS App Development Certification Training www.edureka.co/ios-development
If
If-Else
Switch
If is the most simple decision making statement that decides whether a certain statement or block
of statements will be executed or not.
If
Nested If
Conditional Statements - If
iOS App Development Certification Training www.edureka.co/ios-development
If
If-Else
Switch
It is an if statement or an if-else statement within an if statement.
If
Nested If
Conditional Statements – Nested If
iOS App Development Certification Training www.edureka.co/ios-development
If
If-Else
Switch
If-else tests the condition and if the condition is false then ‘else’ statement is executed.
Conditional Statements – If…else
If-Else
If else ladder
iOS App Development Certification Training www.edureka.co/ios-development
If
If-Else
Switch
If-else-if ladder allows the user to use many if else statement within a loop and in case one of the
condition holds true the rest of the loops is bypassed.
If-Else
If else ladder
Conditional Statements – If…else…if…else
iOS App Development Certification Training www.edureka.co/ios-development
If
If-Else
Switch
The switch statement provides an easy way to execute conditions to different parts of the code.
Conditional Statements – Switch
iOS App Development Certification Training www.edureka.co/ios-development
ITERATIVE
LOOPS
For-in
While
Do-While
iOS App Development Certification Training www.edureka.co/ios-development
Iterative Loops – For-in
For-in
While
Do-While
The for-in loop iterates over collections of items, such as ranges of numbers, items in an array, or
characters in a string.
iOS App Development Certification Training www.edureka.co/ios-development
Iterative Loops – While
For-in
While
Do-While
A while loop statement in Swift programming language repeatedly executes a target statement as
long as a given condition is true.
iOS App Development Certification Training www.edureka.co/ios-development
Iterative Loops – Do-While/ Repeat-While
For-in
While
Do-While
Unlike for and while loops, which test the loop condition at the top of the loop, the repeat...while loop
checks its condition at the bottom of the loop.
iOS App Development Certification Training www.edureka.co/ios-development
ARRAYS &
Tuples
iOS App Development Certification Training www.edureka.co/ios-development
Arrays
An array is a data structure that contains a list of elements. These elements are all of the same
data type, such as an integer or string.
//Creating Arrays
var someArray = [SomeType]()
//Accessing Arrays
var someVar = someArray[index]
Syntax:
iOS App Development Certification Training www.edureka.co/ios-development
Tuples
Tuples are used to group multiple values in a single compound value.
//Declaring Tuples
var TupleName = (Value1, value2,… any number of values)
Example:
Syntax:
//Tuple Declaration
var fail101 = (101, “Values missing”)
print(“The code is(fail101.0)”) // Accessing the values of Tuples
print(“The definition of error is(fail101.1)”)
var fail101 = (failCode: 101, description: “Values missing”)
print(fail101.failCode) // prints 101
iOS App Development Certification Training www.edureka.co/ios-development
SETS &
DICTIONARIES
iOS App Development Certification Training www.edureka.co/ios-development
Sets
❑ Sets are used to store distinct values of same types, but they don’t have definite ordering as arrays.
❑ So, you can use sets instead of arrays if ordering of elements is not an issue, or if you want to
ensure that there are no duplicate values.
//Creating Sets
var exampleSet = Set<Character>()
Syntax:
Access & Modify Sets Iterate over a Set Perform Set Operations
iOS App Development Certification Training www.edureka.co/ios-development
Set Operations
a b
a b
a b
a.union(b)
a.intersection(b)
a.subtracting(b)
a b
a.symmetricDifference(b)
iOS App Development Certification Training www.edureka.co/ios-development
Dictionaries
❑ Dictionaries are used to store unordered lists of values of the same type.
❑ Swift does not allow you to enter a wrong type in a dictionary even by mistake.
VALUE//Creating Sets
var someDict = [KeyType: ValueType]()
var someDict = [Int: String]()
Syntax:
Example:
var someDict:[Int:String] = [1:"One", 2:"Two", 3:"Three"]
iOS App Development Certification Training www.edureka.co/ios-development
FUNCTIONS
iOS App Development Certification Training www.edureka.co/ios-development
Functions
A function is a set of statements organized together to perform a specific task.
func funcname(Parameters) -> returntype {
Statement1
Statement2
---
Statement N
return parameters
Syntax:
Call a Function
Functions with/without Parameters
Functions with/without Return
Values
Function Types
Nested Functions
iOS App Development Certification Training www.edureka.co/ios-development
CLOSURES &
STRUCTURES
iOS App Development Certification Training www.edureka.co/ios-development
Closures
Closures in Swift are similar to that of self-contained functions organized as blocks and called
anywhere like C and Objective C languages.
{
(parameters) −> return type in statements
}
Syntax:
These functions have a name
and do not capture any
values.
They have a name and
capture values from
enclosing function
They are unnamed closures
that capture values from the
adjacent blocks.
Global Functions Nested Functions Closure Expressions
iOS App Development Certification Training www.edureka.co/ios-development
Structures
Swift provides a flexible building block of making use of constructs as Structures. By making use of
structures once can define constructs methods and properties.
struct nameStruct {
Definition 1
Definition 2
---
Definition N }
Syntax:
iOS App Development Certification Training www.edureka.co/ios-development
CLASS &
INHERITANCE
iOS App Development Certification Training www.edureka.co/ios-development
Class
Classes in Swift are building blocks of flexible constructs. Similar to constants, variables and
functions the user can define class properties and methods.
Class classname {
Definition 1
Definition 2
---
Definition N
}
Syntax:
Inheritance acquires
the properties of one
class to another class
Benefits
iOS App Development Certification Training www.edureka.co/ios-development
Class
Classes in Swift are building blocks of flexible constructs. Similar to constants, variables and
functions the user can define class properties and methods.
Type casting enables
the user to check class
type at run time.
Benefits
Class classname {
Definition 1
Definition 2
---
Definition N
}
Syntax:
iOS App Development Certification Training www.edureka.co/ios-development
Class
Classes in Swift are building blocks of flexible constructs. Similar to constants, variables and
functions the user can define class properties and methods. Benefits
Reference counting
allows the class
instance to have more
than one reference
Class classname {
Definition 1
Definition 2
---
Definition N
}
Syntax:
iOS App Development Certification Training www.edureka.co/ios-development
Inheritance
Inheritance is the process of creating new classes, called derived classes, from existing classes or
base classes. The derived class inherits all the capabilities of the base class, but can add
embellishments and refinements of its own.
Sub class Super class
If a class inherits properties, methods and
functions from another class, then it is
called as sub class.
Class containing properties, methods and
functions to inherit other classes from
itself is called as a super class.
iOS App Development Certification Training www.edureka.co/ios-development
PROTOCOLS
iOS App Development Certification Training www.edureka.co/ios-development
Protocols
❑ Protocols provide a blueprint for Methods, properties and other requirements functionality.
❑ It is just described as a methods or properties skeleton instead of implementation.
protocol ExampleProtocol {
// protocol definition }
// Mulitple protocol declarations
struct SomeStructure: Protocol1, Protocol2 {
// structure definition }
//Defining protocol for super class
class SomeClass: SomeSuperclass, Protocol1, Protocol2 {
// class definition }
Syntax:
iOS App Development Certification Training www.edureka.co/ios-development
EXTENSIONS
iOS App Development Certification Training www.edureka.co/ios-development
Extensions
❑ Extensions are used to add the functionalities of an existing class, structure or enumeration
type.
❑ Type functionality can be added with extensions but, overriding the functionality is not
possible with extensions.
extension ExampleType {
// new functionality can be added here
}
Syntax:
Defining
subscripts
Adding
computed
properties.
Defining
and using
new
nested
types
Making an
existing
type
protocol.
Defining
instance
and type
methods
Provide
new
initializers.
FUNCTIONALITIES
iOS App Development Certification Training www.edureka.co/ios-development
GENERICS
iOS App Development Certification Training www.edureka.co/ios-development
Generics
❑ Swift language provides 'Generic' features to write flexible and reusable functions and types.
❑ Generics are used to avoid duplication and to provide abstraction
iOS App Development Certification Training www.edureka.co/ios-development
ENUMERATIONS
iOS App Development Certification Training www.edureka.co/ios-development
Enumerations
❑ An enumeration is a user-defined data type which consists of set of related values.
❑ Keyword enum is used to defined enumerated data type.
enum enumname {
// enumeration values are described here
}
Syntax:
Swift Tutorial For Beginners | Swift Programming Tutorial | IOS App Development Tutorial | Edureka

More Related Content

PPT
Swift Introduction
PPTX
middle cerebral artery anatomy
PPT
iOS Introduction For Very Beginners
PPTX
SQL commands
PPTX
GDSC Flutter Forward Workshop.pptx
PPTX
Python Seminar PPT
PPTX
Cerebral aneurysm
PPTX
Intro to Flutter SDK
Swift Introduction
middle cerebral artery anatomy
iOS Introduction For Very Beginners
SQL commands
GDSC Flutter Forward Workshop.pptx
Python Seminar PPT
Cerebral aneurysm
Intro to Flutter SDK

What's hot (20)

PDF
Swift Programming Language
PPTX
Introduction to Spring Framework
PPTX
Swift programming language
ODP
Introduction to Spring Framework and Spring IoC
PPT
Spring ppt
PPTX
Introduction to Node.js
PDF
UI controls in Android
PPSX
PPTX
Core java complete ppt(note)
PPT
C#.NET
PPTX
Introduction to java
PPTX
Hibernate ppt
PPT
Ppt of soap ui
PPT
Ios development
PPTX
What is component in reactjs
PDF
Manipulating Android tasks and back stack
PPT
Java Swing JFC
PPT
Java collections concept
PPTX
Angularjs PPT
PPTX
iOS Architecture
Swift Programming Language
Introduction to Spring Framework
Swift programming language
Introduction to Spring Framework and Spring IoC
Spring ppt
Introduction to Node.js
UI controls in Android
Core java complete ppt(note)
C#.NET
Introduction to java
Hibernate ppt
Ppt of soap ui
Ios development
What is component in reactjs
Manipulating Android tasks and back stack
Java Swing JFC
Java collections concept
Angularjs PPT
iOS Architecture
Ad

Similar to Swift Tutorial For Beginners | Swift Programming Tutorial | IOS App Development Tutorial | Edureka (20)

PDF
Using Swift for all Apple platforms (iOS, watchOS, tvOS and OS X)
PPTX
presentationofswift.pptx
PPTX
Tech breakfast 18
PPTX
Why Swift Is the Most Preferred Choice of Developers For iOS App Development?
PDF
The swift programming language
PDF
java training in chandigarh
DOCX
iOS certification competitive tests and interview questions
PPTX
JAVA introduction and basic understanding.pptx
PPTX
Swift, a Swift Sample
PDF
The Swift Programming Language - Xcode6 for iOS App Development - AgileInfowa...
PDF
Ashok_Vardhan_Cheemakurthy
PPTX
Std 12 Computer Chapter 7 Java Basics (Part 1)
PPTX
JAVA PROGRAMMING-Unit I - Final PPT.pptx
PDF
iOS Development Using Swift 2
PPTX
PPT.pptxvkjvwbjbbikvhixhkiheihhiiihwxhhi
PPTX
Intro to appcelerator
PDF
Swift vs flutter pixel values technolabs
PDF
Java Simplified: Understanding Programming Basics
PPTX
Modern_2.pptx for java
Using Swift for all Apple platforms (iOS, watchOS, tvOS and OS X)
presentationofswift.pptx
Tech breakfast 18
Why Swift Is the Most Preferred Choice of Developers For iOS App Development?
The swift programming language
java training in chandigarh
iOS certification competitive tests and interview questions
JAVA introduction and basic understanding.pptx
Swift, a Swift Sample
The Swift Programming Language - Xcode6 for iOS App Development - AgileInfowa...
Ashok_Vardhan_Cheemakurthy
Std 12 Computer Chapter 7 Java Basics (Part 1)
JAVA PROGRAMMING-Unit I - Final PPT.pptx
iOS Development Using Swift 2
PPT.pptxvkjvwbjbbikvhixhkiheihhiiihwxhhi
Intro to appcelerator
Swift vs flutter pixel values technolabs
Java Simplified: Understanding Programming Basics
Modern_2.pptx for java
Ad

More from Edureka! (20)

PDF
What to learn during the 21 days Lockdown | Edureka
PDF
Top 10 Dying Programming Languages in 2020 | Edureka
PDF
Top 5 Trending Business Intelligence Tools | Edureka
PDF
Tableau Tutorial for Data Science | Edureka
PDF
Python Programming Tutorial | Edureka
PDF
Top 5 PMP Certifications | Edureka
PDF
Top Maven Interview Questions in 2020 | Edureka
PDF
Linux Mint Tutorial | Edureka
PDF
How to Deploy Java Web App in AWS| Edureka
PDF
Importance of Digital Marketing | Edureka
PDF
RPA in 2020 | Edureka
PDF
Email Notifications in Jenkins | Edureka
PDF
EA Algorithm in Machine Learning | Edureka
PDF
Cognitive AI Tutorial | Edureka
PDF
AWS Cloud Practitioner Tutorial | Edureka
PDF
Blue Prism Top Interview Questions | Edureka
PDF
Big Data on AWS Tutorial | Edureka
PDF
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
PDF
Kubernetes Installation on Ubuntu | Edureka
PDF
Introduction to DevOps | Edureka
What to learn during the 21 days Lockdown | Edureka
Top 10 Dying Programming Languages in 2020 | Edureka
Top 5 Trending Business Intelligence Tools | Edureka
Tableau Tutorial for Data Science | Edureka
Python Programming Tutorial | Edureka
Top 5 PMP Certifications | Edureka
Top Maven Interview Questions in 2020 | Edureka
Linux Mint Tutorial | Edureka
How to Deploy Java Web App in AWS| Edureka
Importance of Digital Marketing | Edureka
RPA in 2020 | Edureka
Email Notifications in Jenkins | Edureka
EA Algorithm in Machine Learning | Edureka
Cognitive AI Tutorial | Edureka
AWS Cloud Practitioner Tutorial | Edureka
Blue Prism Top Interview Questions | Edureka
Big Data on AWS Tutorial | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
Kubernetes Installation on Ubuntu | Edureka
Introduction to DevOps | Edureka

Recently uploaded (20)

PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
Cloud computing and distributed systems.
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
A Presentation on Artificial Intelligence
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
cuic standard and advanced reporting.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Machine learning based COVID-19 study performance prediction
PPTX
Big Data Technologies - Introduction.pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
NewMind AI Monthly Chronicles - July 2025
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Cloud computing and distributed systems.
Building Integrated photovoltaic BIPV_UPV.pdf
The AUB Centre for AI in Media Proposal.docx
A Presentation on Artificial Intelligence
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
cuic standard and advanced reporting.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
NewMind AI Weekly Chronicles - August'25 Week I
Machine learning based COVID-19 study performance prediction
Big Data Technologies - Introduction.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
The Rise and Fall of 3GPP – Time for a Sabbatical?
NewMind AI Monthly Chronicles - July 2025
“AI and Expert System Decision Support & Business Intelligence Systems”
Dropbox Q2 2025 Financial Results & Investor Presentation
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication

Swift Tutorial For Beginners | Swift Programming Tutorial | IOS App Development Tutorial | Edureka

  • 1. iOS App Development Certification Training www.edureka.co/ios-development
  • 2. iOS App Development Certification Training www.edureka.co/ios-development Topics For Today’s Session What is Swift? Xcode IDE Swift Fundamentals
  • 3. iOS App Development Certification Training www.edureka.co/ios-development What is Swift? ❑ Swift is a programming language developed by Apple Inc for iOS and OS X development. ❑ Swift adopts the best of C and Objective-C, without the constraints of C compatibility. ❑ Swift uses the same runtime as the existing Objective-C system on Mac OS and iOS, which enables programs to run on many existing iOS 6 and OS X 10.8 platforms.
  • 4. iOS App Development Certification Training www.edureka.co/ios-development Xcode IDE ❑ Xcode is an IDE for macOS , which contains a suite of software development tools developed by Apple. ❑ This set of tools developed are used for developing software for macOS, iOS, watchOS, and tvOS.
  • 5. iOS App Development Certification Training www.edureka.co/ios-development BASIC SYNTAX White Spaces Semicolons Literals Identifiers Tokens Keywords Comments
  • 6. iOS App Development Certification Training www.edureka.co/ios-development Swift Basic Syntax print("test!") The individual tokens are: print("test!") White Spaces Semicolons Literals Identifiers Tokens Keywords Comments ❑ A Swift program can consists of various number of tokens. ❑ A token is either a keyword, an identifier, a constant, a string literal, or a symbol. Example:
  • 7. iOS App Development Certification Training www.edureka.co/ios-development Swift Basic Syntax White Spaces Semicolons Literals Identifiers Tokens Keywords Comments // This is the syntax for single-line comments. /* This is the syntax for multi-line comments. */ /* This is the syntax for nested /* multi-line comments. */ */ ❑ Comments are like helping texts in a Swift program which are ignored by the compiler. ❑ Multi-line comments start with /* and terminate with the characters */ where as Single-line comments are written using // at the beginning of the comment. Example:
  • 8. iOS App Development Certification Training www.edureka.co/ios-development Swift Basic Syntax White Spaces Semicolons Literals Identifiers Tokens Keywords Comments ❑ Swift does not require you to type a semicolon (;) after each statement in the code. ❑ If you use multiple statements in the same line, then semicolon is used as a delimiter. /* Using two statements in the same line*/ var myString = "Hello, World!";print(myString) Example:
  • 9. iOS App Development Certification Training www.edureka.co/ios-development Swift Basic Syntax White Spaces Semicolons Literals Identifiers Tokens Keywords Comments ❑ An identifier starts with an alphabet A to Z or a to z or an underscore _ followed by zero or more letters, underscores, and digits (0 to 9). ❑ Swift is a case-sensitive language does not allow special characters such as @, $, and % within identifiers. Example: Sahiti kappagantula xyz emp_name a_123 hello10 _abc y d12e8 returnVal _123_abc
  • 10. iOS App Development Certification Training www.edureka.co/ios-development Swift Basic Syntax White Spaces Semicolons Literals Identifiers Tokens Keywords Comments Keywords are reserved words which may not be used as constants or variables or any other identifier names, unless they're escaped with backticks. Keywords Used In Declarations Class deinit Enum extension Func Let import Init internal public typealias operator private protocol var subscript static struct subscript Keywords Used In Statements break case continue default do if else fallthrough for where while in return switch Keywords Used In Expressions And Types as dynamicType false is true nil self Self super _FUNCTION_ _LINE_ _COLUMN_ _FILE_ Keywords Used In Particular Contexts associativity convenience dynamic didSet precedence final get infix inout prefix lazy left mutating none Protocol nonmutating optional override postfix required right set Type unowned weak
  • 11. iOS App Development Certification Training www.edureka.co/ios-development Swift Basic Syntax White Spaces Semicolons Literals Identifiers Tokens Keywords Comments ❑ Whitespace is the term used in Swift to describe blanks, tabs, newline characters, and comments. ❑ Whitespaces separate one part of a statement from another and enable the compiler to identify where one element in a statement, ends and the next element begins. int age = a + b //Correct Statement int age = a +b //Incorrect Statement Example:
  • 12. iOS App Development Certification Training www.edureka.co/ios-development Swift Basic Syntax White Spaces Semicolons Literals Identifiers Tokens Keywords Comments ❑ A literal is the source code representation of a value of an integer, floating-point number, or string type. 72 // Integer literal 8.14659 // Floating-point literal Hello, World!" // String literal Example: Integer Literal Floating Literals String Literals Boolean Literals
  • 13. iOS App Development Certification Training www.edureka.co/ios-development VARIABLES, DATATYPES & TYPE CASTING
  • 14. iOS App Development Certification Training www.edureka.co/ios-development VARIABLES ❑ A variable provides us with named storage that our programs can manipulate. ❑ Each variable in Swift has a specific type, which determines the size and layout of the variable's memory. var variableName = <initial value> //We can also mention Type Annotations var variableName:<data type> = <optional initial value> Syntax:
  • 15. iOS App Development Certification Training www.edureka.co/ios-development Data Types The Built-In Data Types are Int or UInt, Float, Double, Bool, String, Character, Optional, and Tuples. Type Typical Bit Width Typical Range Int8 1byte -127 to 127 UInt8 1byte 0 to 255 Int32 4bytes -2147483648 to 2147483647 UInt32 4bytes 0 to 4294967295 Int64 8bytes -9223372036854775808 to 9223372036854775807 UInt64 8bytes 0 to 18446744073709551615 Float 4bytes 1.2E-38 to 3.4E+38 (~6 digits) Double 8bytes 2.3E-308 to 1.7E+308 (~15 digits)
  • 16. iOS App Development Certification Training www.edureka.co/ios-development Data Types typealias newname = type typealias Feet = Int var distance: Feet = 500 print(distance) Type Inference var varA = 42 print(varA) varB = 3.14159 print(varB) Type Safety var varX = 67 varX = “Hi There" print(varX) Type Aliases main.swift:2:8: error: cannot assign value of type 'String' to type 'Int' varX = “Hi There”
  • 17. iOS App Development Certification Training www.edureka.co/ios-development Type Casting Type Casting in simple terms is converting one data type into another data type. let a: Int = 5679 let b: Float = 2.9999 print(“This number is an Int now (Int(b))”) print(“This number is a Float now (Float(a))”) let myAge = “17.5” //Convert String To Integer & Float let myAgeConvInt = myAge.toInt() let myAgeConvFloat = (myAge as NSString).floatValue Example:
  • 18. iOS App Development Certification Training www.edureka.co/ios-development OPERATORS Arithmetic Comparison Logical Bitwise Assignment Range Misc
  • 19. iOS App Development Certification Training www.edureka.co/ios-development Arithmetic Operators Arithmetic Comparison Logical Bitwise Assignment Range Misc + - * / % == != > < >= <= && || ! & | ^ ~ << >> = += -= *= /= %= <<= >>= &= ^= != Closed Range Half-Open Range One-Sided Range Unary Minus Unary Plus Ternary Conditional
  • 20. iOS App Development Certification Training www.edureka.co/ios-development CONDITIONAL STATEMENTS If If-Else Switch
  • 21. iOS App Development Certification Training www.edureka.co/ios-development If If-Else Switch If is the most simple decision making statement that decides whether a certain statement or block of statements will be executed or not. If Nested If Conditional Statements - If
  • 22. iOS App Development Certification Training www.edureka.co/ios-development If If-Else Switch It is an if statement or an if-else statement within an if statement. If Nested If Conditional Statements – Nested If
  • 23. iOS App Development Certification Training www.edureka.co/ios-development If If-Else Switch If-else tests the condition and if the condition is false then ‘else’ statement is executed. Conditional Statements – If…else If-Else If else ladder
  • 24. iOS App Development Certification Training www.edureka.co/ios-development If If-Else Switch If-else-if ladder allows the user to use many if else statement within a loop and in case one of the condition holds true the rest of the loops is bypassed. If-Else If else ladder Conditional Statements – If…else…if…else
  • 25. iOS App Development Certification Training www.edureka.co/ios-development If If-Else Switch The switch statement provides an easy way to execute conditions to different parts of the code. Conditional Statements – Switch
  • 26. iOS App Development Certification Training www.edureka.co/ios-development ITERATIVE LOOPS For-in While Do-While
  • 27. iOS App Development Certification Training www.edureka.co/ios-development Iterative Loops – For-in For-in While Do-While The for-in loop iterates over collections of items, such as ranges of numbers, items in an array, or characters in a string.
  • 28. iOS App Development Certification Training www.edureka.co/ios-development Iterative Loops – While For-in While Do-While A while loop statement in Swift programming language repeatedly executes a target statement as long as a given condition is true.
  • 29. iOS App Development Certification Training www.edureka.co/ios-development Iterative Loops – Do-While/ Repeat-While For-in While Do-While Unlike for and while loops, which test the loop condition at the top of the loop, the repeat...while loop checks its condition at the bottom of the loop.
  • 30. iOS App Development Certification Training www.edureka.co/ios-development ARRAYS & Tuples
  • 31. iOS App Development Certification Training www.edureka.co/ios-development Arrays An array is a data structure that contains a list of elements. These elements are all of the same data type, such as an integer or string. //Creating Arrays var someArray = [SomeType]() //Accessing Arrays var someVar = someArray[index] Syntax:
  • 32. iOS App Development Certification Training www.edureka.co/ios-development Tuples Tuples are used to group multiple values in a single compound value. //Declaring Tuples var TupleName = (Value1, value2,… any number of values) Example: Syntax: //Tuple Declaration var fail101 = (101, “Values missing”) print(“The code is(fail101.0)”) // Accessing the values of Tuples print(“The definition of error is(fail101.1)”) var fail101 = (failCode: 101, description: “Values missing”) print(fail101.failCode) // prints 101
  • 33. iOS App Development Certification Training www.edureka.co/ios-development SETS & DICTIONARIES
  • 34. iOS App Development Certification Training www.edureka.co/ios-development Sets ❑ Sets are used to store distinct values of same types, but they don’t have definite ordering as arrays. ❑ So, you can use sets instead of arrays if ordering of elements is not an issue, or if you want to ensure that there are no duplicate values. //Creating Sets var exampleSet = Set<Character>() Syntax: Access & Modify Sets Iterate over a Set Perform Set Operations
  • 35. iOS App Development Certification Training www.edureka.co/ios-development Set Operations a b a b a b a.union(b) a.intersection(b) a.subtracting(b) a b a.symmetricDifference(b)
  • 36. iOS App Development Certification Training www.edureka.co/ios-development Dictionaries ❑ Dictionaries are used to store unordered lists of values of the same type. ❑ Swift does not allow you to enter a wrong type in a dictionary even by mistake. VALUE//Creating Sets var someDict = [KeyType: ValueType]() var someDict = [Int: String]() Syntax: Example: var someDict:[Int:String] = [1:"One", 2:"Two", 3:"Three"]
  • 37. iOS App Development Certification Training www.edureka.co/ios-development FUNCTIONS
  • 38. iOS App Development Certification Training www.edureka.co/ios-development Functions A function is a set of statements organized together to perform a specific task. func funcname(Parameters) -> returntype { Statement1 Statement2 --- Statement N return parameters Syntax: Call a Function Functions with/without Parameters Functions with/without Return Values Function Types Nested Functions
  • 39. iOS App Development Certification Training www.edureka.co/ios-development CLOSURES & STRUCTURES
  • 40. iOS App Development Certification Training www.edureka.co/ios-development Closures Closures in Swift are similar to that of self-contained functions organized as blocks and called anywhere like C and Objective C languages. { (parameters) −> return type in statements } Syntax: These functions have a name and do not capture any values. They have a name and capture values from enclosing function They are unnamed closures that capture values from the adjacent blocks. Global Functions Nested Functions Closure Expressions
  • 41. iOS App Development Certification Training www.edureka.co/ios-development Structures Swift provides a flexible building block of making use of constructs as Structures. By making use of structures once can define constructs methods and properties. struct nameStruct { Definition 1 Definition 2 --- Definition N } Syntax:
  • 42. iOS App Development Certification Training www.edureka.co/ios-development CLASS & INHERITANCE
  • 43. iOS App Development Certification Training www.edureka.co/ios-development Class Classes in Swift are building blocks of flexible constructs. Similar to constants, variables and functions the user can define class properties and methods. Class classname { Definition 1 Definition 2 --- Definition N } Syntax: Inheritance acquires the properties of one class to another class Benefits
  • 44. iOS App Development Certification Training www.edureka.co/ios-development Class Classes in Swift are building blocks of flexible constructs. Similar to constants, variables and functions the user can define class properties and methods. Type casting enables the user to check class type at run time. Benefits Class classname { Definition 1 Definition 2 --- Definition N } Syntax:
  • 45. iOS App Development Certification Training www.edureka.co/ios-development Class Classes in Swift are building blocks of flexible constructs. Similar to constants, variables and functions the user can define class properties and methods. Benefits Reference counting allows the class instance to have more than one reference Class classname { Definition 1 Definition 2 --- Definition N } Syntax:
  • 46. iOS App Development Certification Training www.edureka.co/ios-development Inheritance Inheritance is the process of creating new classes, called derived classes, from existing classes or base classes. The derived class inherits all the capabilities of the base class, but can add embellishments and refinements of its own. Sub class Super class If a class inherits properties, methods and functions from another class, then it is called as sub class. Class containing properties, methods and functions to inherit other classes from itself is called as a super class.
  • 47. iOS App Development Certification Training www.edureka.co/ios-development PROTOCOLS
  • 48. iOS App Development Certification Training www.edureka.co/ios-development Protocols ❑ Protocols provide a blueprint for Methods, properties and other requirements functionality. ❑ It is just described as a methods or properties skeleton instead of implementation. protocol ExampleProtocol { // protocol definition } // Mulitple protocol declarations struct SomeStructure: Protocol1, Protocol2 { // structure definition } //Defining protocol for super class class SomeClass: SomeSuperclass, Protocol1, Protocol2 { // class definition } Syntax:
  • 49. iOS App Development Certification Training www.edureka.co/ios-development EXTENSIONS
  • 50. iOS App Development Certification Training www.edureka.co/ios-development Extensions ❑ Extensions are used to add the functionalities of an existing class, structure or enumeration type. ❑ Type functionality can be added with extensions but, overriding the functionality is not possible with extensions. extension ExampleType { // new functionality can be added here } Syntax: Defining subscripts Adding computed properties. Defining and using new nested types Making an existing type protocol. Defining instance and type methods Provide new initializers. FUNCTIONALITIES
  • 51. iOS App Development Certification Training www.edureka.co/ios-development GENERICS
  • 52. iOS App Development Certification Training www.edureka.co/ios-development Generics ❑ Swift language provides 'Generic' features to write flexible and reusable functions and types. ❑ Generics are used to avoid duplication and to provide abstraction
  • 53. iOS App Development Certification Training www.edureka.co/ios-development ENUMERATIONS
  • 54. iOS App Development Certification Training www.edureka.co/ios-development Enumerations ❑ An enumeration is a user-defined data type which consists of set of related values. ❑ Keyword enum is used to defined enumerated data type. enum enumname { // enumeration values are described here } Syntax: