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

What's hot (20)

Swift Programming Language
Swift Programming Language
Giuseppe Arici
 
Swift Programming Language
Swift Programming Language
Anıl Sözeri
 
Swift Tutorial Part 1. The Complete Guide For Swift Programming Language
Swift Tutorial Part 1. The Complete Guide For Swift Programming Language
Hossam Ghareeb
 
Introduction to java
Introduction to java
Sandeep Rawat
 
SQLITE Android
SQLITE Android
Sourabh Sahu
 
Spring AOP
Spring AOP
AnushaNaidu
 
Use Node.js to create a REST API
Use Node.js to create a REST API
Fabien Vauchelles
 
Spring Boot
Spring Boot
Jiayun Zhou
 
Spring AOP
Spring AOP
Tata Consultancy Services
 
iOS Operating System
iOS Operating System
Jawaher Abdulwahab Fadhil
 
Spring annotation
Spring annotation
Rajiv Srivastava
 
Spring ppt
Spring ppt
Mumbai Academisc
 
UI controls in Android
UI controls in Android
DivyaKS12
 
Arrays in java
Arrays in java
Arzath Areeff
 
Introduction to JAVA
Introduction to JAVA
ParminderKundu
 
Mobile application development
Mobile application development
Eric Cattoir
 
Eclipse introduction IDE PRESENTATION
Eclipse introduction IDE PRESENTATION
AYESHA JAVED
 
JAVA PROGRAMMING
JAVA PROGRAMMING
Niyitegekabilly
 
java 8 new features
java 8 new features
Rohit Verma
 
Ios development
Ios development
Shakil Ahmed
 

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

The Swift Programming Language - Xcode6 for iOS App Development - AgileInfowa...
The Swift Programming Language - Xcode6 for iOS App Development - AgileInfowa...
Mark Simon
 
Unit 1 - Getting Started with App Development
Unit 1 - Getting Started with App Development
Franco Cedillo
 
The swift programming language
The swift programming language
Pardeep Chaudhary
 
Developing iOS apps with Swift
Developing iOS apps with Swift
New Generation Applications
 
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 02)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 02)
Jonathan Engelsma
 
Download Full iOS 14 Programming Fundamentals with Swift Covers iOS 14 Xcode ...
Download Full iOS 14 Programming Fundamentals with Swift Covers iOS 14 Xcode ...
vignelordi07
 
iOS 9 Programming Fundamentals with Swift Swift Xcode and Cocoa Basics 2nd Ed...
iOS 9 Programming Fundamentals with Swift Swift Xcode and Cocoa Basics 2nd Ed...
mycielyonne
 
iOS 9 Programming Fundamentals with Swift Swift Xcode and Cocoa Basics 2nd Ed...
iOS 9 Programming Fundamentals with Swift Swift Xcode and Cocoa Basics 2nd Ed...
jussiefathey
 
Intro toswift1
Intro toswift1
Jordan Morgan
 
Ios 12 Programming Fundamentals With Swift Swift Xcode And Cocoa Basics 5th E...
Ios 12 Programming Fundamentals With Swift Swift Xcode And Cocoa Basics 5th E...
joettealhadi
 
Build Your First iOS App With Swift
Build Your First iOS App With Swift
Edureka!
 
iOS 9 Programming Fundamentals with Swift Swift Xcode and Cocoa Basics 2nd Ed...
iOS 9 Programming Fundamentals with Swift Swift Xcode and Cocoa Basics 2nd Ed...
exzanyangdi
 
Developer’s viewpoint on swift programming language
Developer’s viewpoint on swift programming language
Azilen Technologies Pvt. Ltd.
 
Swift, swiftly
Swift, swiftly
Jack Nutting
 
The Importance of Swift Programming Language in iOS App Development
The Importance of Swift Programming Language in iOS App Development
Ubuy Academy
 
Ios training-cum-course-in-mumbai-
Ios training-cum-course-in-mumbai-
vibrantuser
 
Introduction to Swift (tutorial)
Introduction to Swift (tutorial)
Bruno Delb
 
Swift Tutorial Free For You To Use Brooo
Swift Tutorial Free For You To Use Brooo
l3noneone
 
Workhop iOS 1: Fundamentos de Swift
Workhop iOS 1: Fundamentos de Swift
Visual Engineering
 
Start with swift
Start with swift
Arti Yadav I am looking for new Projects
 
The Swift Programming Language - Xcode6 for iOS App Development - AgileInfowa...
The Swift Programming Language - Xcode6 for iOS App Development - AgileInfowa...
Mark Simon
 
Unit 1 - Getting Started with App Development
Unit 1 - Getting Started with App Development
Franco Cedillo
 
The swift programming language
The swift programming language
Pardeep Chaudhary
 
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 02)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 02)
Jonathan Engelsma
 
Download Full iOS 14 Programming Fundamentals with Swift Covers iOS 14 Xcode ...
Download Full iOS 14 Programming Fundamentals with Swift Covers iOS 14 Xcode ...
vignelordi07
 
iOS 9 Programming Fundamentals with Swift Swift Xcode and Cocoa Basics 2nd Ed...
iOS 9 Programming Fundamentals with Swift Swift Xcode and Cocoa Basics 2nd Ed...
mycielyonne
 
iOS 9 Programming Fundamentals with Swift Swift Xcode and Cocoa Basics 2nd Ed...
iOS 9 Programming Fundamentals with Swift Swift Xcode and Cocoa Basics 2nd Ed...
jussiefathey
 
Ios 12 Programming Fundamentals With Swift Swift Xcode And Cocoa Basics 5th E...
Ios 12 Programming Fundamentals With Swift Swift Xcode And Cocoa Basics 5th E...
joettealhadi
 
Build Your First iOS App With Swift
Build Your First iOS App With Swift
Edureka!
 
iOS 9 Programming Fundamentals with Swift Swift Xcode and Cocoa Basics 2nd Ed...
iOS 9 Programming Fundamentals with Swift Swift Xcode and Cocoa Basics 2nd Ed...
exzanyangdi
 
Developer’s viewpoint on swift programming language
Developer’s viewpoint on swift programming language
Azilen Technologies Pvt. Ltd.
 
The Importance of Swift Programming Language in iOS App Development
The Importance of Swift Programming Language in iOS App Development
Ubuy Academy
 
Ios training-cum-course-in-mumbai-
Ios training-cum-course-in-mumbai-
vibrantuser
 
Introduction to Swift (tutorial)
Introduction to Swift (tutorial)
Bruno Delb
 
Swift Tutorial Free For You To Use Brooo
Swift Tutorial Free For You To Use Brooo
l3noneone
 
Workhop iOS 1: Fundamentos de Swift
Workhop iOS 1: Fundamentos de Swift
Visual Engineering
 
Ad

More from Edureka! (20)

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

Recently uploaded (20)

AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
SOFTTECHHUB
 
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
Safe Software
 
Reducing Conflicts and Increasing Safety Along the Cycling Networks of East-F...
Reducing Conflicts and Increasing Safety Along the Cycling Networks of East-F...
Safe Software
 
FME for Good: Integrating Multiple Data Sources with APIs to Support Local Ch...
FME for Good: Integrating Multiple Data Sources with APIs to Support Local Ch...
Safe Software
 
PyData - Graph Theory for Multi-Agent Integration
PyData - Graph Theory for Multi-Agent Integration
barqawicloud
 
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Alliance
 
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
biswajitbanerjee38
 
“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...
“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...
Edge AI and Vision Alliance
 
Murdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementary
JorgeSemperteguiMont
 
Providing an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME Flow
Safe Software
 
Edge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdf
AmirStern2
 
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
angelo60207
 
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Anish Kumar
 
Your startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean account
angelo60207
 
Oracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI Professional
VICTOR MAESTRE RAMIREZ
 
Supporting the NextGen 911 Digital Transformation with FME
Supporting the NextGen 911 Digital Transformation with FME
Safe Software
 
Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025
Safe Software
 
MuleSoft for AgentForce : Topic Center and API Catalog
MuleSoft for AgentForce : Topic Center and API Catalog
shyamraj55
 
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Shashikant Jagtap
 
Oracle Cloud Infrastructure AI Foundations
Oracle Cloud Infrastructure AI Foundations
VICTOR MAESTRE RAMIREZ
 
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
SOFTTECHHUB
 
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
Safe Software
 
Reducing Conflicts and Increasing Safety Along the Cycling Networks of East-F...
Reducing Conflicts and Increasing Safety Along the Cycling Networks of East-F...
Safe Software
 
FME for Good: Integrating Multiple Data Sources with APIs to Support Local Ch...
FME for Good: Integrating Multiple Data Sources with APIs to Support Local Ch...
Safe Software
 
PyData - Graph Theory for Multi-Agent Integration
PyData - Graph Theory for Multi-Agent Integration
barqawicloud
 
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Alliance
 
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
biswajitbanerjee38
 
“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...
“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...
Edge AI and Vision Alliance
 
Murdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementary
JorgeSemperteguiMont
 
Providing an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME Flow
Safe Software
 
Edge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdf
AmirStern2
 
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
angelo60207
 
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Anish Kumar
 
Your startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean account
angelo60207
 
Oracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI Professional
VICTOR MAESTRE RAMIREZ
 
Supporting the NextGen 911 Digital Transformation with FME
Supporting the NextGen 911 Digital Transformation with FME
Safe Software
 
Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025
Safe Software
 
MuleSoft for AgentForce : Topic Center and API Catalog
MuleSoft for AgentForce : Topic Center and API Catalog
shyamraj55
 
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Shashikant Jagtap
 
Oracle Cloud Infrastructure AI Foundations
Oracle Cloud Infrastructure AI Foundations
VICTOR MAESTRE RAMIREZ
 

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: