SWIFT TUTORIAL
Agenda
Comments
Download and Installation
2
First program
3
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
4
Variables
6
Operators
7
Datatypes
5
Introduction
1
Practical
8
Optional Types
9
Conditional Constructs
10
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Introduction
Introduction
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
• Swift is a general purpose programming language for developing iOS applications. It is developed by Apple
Inc.
• It is powerful and intuitive language which is easy to learn.
• Swift is a fantastic way to write software, whether it’s for phones, desktops, servers, or anything else that
runs code.
• Swift follows Objective-C runtime library which allows C, Objective-C, C++ and Swift code to run within one
program.
• Swift 5.4 is the latest version of Swift.
• The compiler is optimized for performance and the language is optimized for development, without
compromising on either.
Introduction
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Swift defines away large classes of common programming errors by adopting modern programming patterns:
• Variables are always initialized before use.
• Array indices are checked for out-of-bounds errors.
• Integers are checked for overflow.
• Optional ensure that nil values are handled explicitly.
• Memory is managed automatically.
• Error handling allows controlled recovery from unexpected failures.
Swift code is compiled and optimized to get the most out of modern hardware. The syntax and standard library
have been designed based on the guiding principle that the obvious way to write your code should also
perform the best.
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Download and Installation
Download and Installation
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
There are mainly two things to download when you want to work with Swift in windows:
1. Swift installer for Windows
2. Visual Studio 2019 Community
Download and Installation
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Go to swift.org – the official website of Swift and download the windows tool chain of it.
Download and Installation
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Go to https://visualstudio.microsoft.com/downloads/ – the official website of Visual studio and download the
Community edition of it.
Download and Installation
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Start the visual studio installer and complete some necessary steps while installing:
Download and Installation
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
This is how the visual studio window will appear when it will be downloaded and installed:
Download and Installation
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Tick ā€œDesktop development with C++ā€.
Download and Installation
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Download and Installation
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Once all requirements are ticked, we can start Installing our visual studio:
Download and Installation
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Now, its time to open swift installer and install swift in our system.
In order to make the Windows SDK accessible to Swift, it is necessary to deploy a few files into the Windows
SDK. The following will modify your Visual Studio Installation, and as such will require to be run from an
(elevated) ā€œAdministratorā€
Because it is installing the files into the Visual Studio image, the files will need to be copied each time Visual
Studio is updated.
Download and Installation
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Download and Installation
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Copy these with copy command and run it in the command prompt:
%SDKROOT%usrshareucrt.modulemap "%UniversalCRTSdkDir%Include%UCRTVersion%ucrtmodule.modulemap"
%SDKROOT%usrsharevisualc.modulemap "%VCToolsInstallDir%includemodule.modulemap"
%SDKROOT%usrsharevisualc.apinotes "%VCToolsInstallDir%includevisualc.apinotes"
%SDKROOT%usrsharewinsdk.modulemap "%UniversalCRTSdkDir%Include%UCRTVersion%ummodule.modulemap"
Download and Installation
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
First Program
First Program
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
- Environments variables for the Swift compiler:
set SWIFTFLAGS=-sdk %SDKROOT% -resource-dir
%SDKROOT%usrlibswift -I %SDKROOT%usrlibswift -L
%SDKROOT%usrlibswiftwindows
- Building a Swift program:
swiftc %SWIFTFLAGS% -emit-executable -o First.exe First.swift
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Comments
Comments
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
The first way to write a comment is:
// This is a comment. It is not executed.
This is a single line comment. You could stack these up like so to allow you to write paragraphs:
// This is also a comment.
// Over multiple lines.
However, there is a better way to write comments that span multiple lines:
/* This is also a comment.
Over many...
many...
many lines. */
This is a multi-line comment. The start is denoted by /* and the end is denoted by */.
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Datatypes
Datatypes
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
• Int or UInt āˆ’ This is used for whole numbers.
Use Int32, Int64 - 32 or 64 bit signed integer
whereas UInt32 or UInt64 - 32 or 64 bit unsigned integer variables.
• Float āˆ’ This is used to represent a 32-bit floating-point number and numbers with smaller decimal points. For
example, 3.14159, 0.1, and -273.158.
• Double āˆ’ This is used to represent a 64-bit floating-point number and used when floating-point values must be
very large. For example, 3.14159, 0.1, and -273.158.
• Bool āˆ’ This represents a Boolean value which is either true or false.
• String āˆ’ This is an ordered collection of characters. For example, "Hello, World!"
• Character āˆ’ This is a single-character string literal. For example, "C"
• Optional āˆ’ This represents a variable that can hold either a value or no value.
• Tuples āˆ’ This is used to group multiple values in single Compound Value.
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Variables
Variables
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
• var variableName = <initial value>
• var siteName:String
siteName = ā€œgreat learning"
print(siteName)
• var siteName = ā€œgreat learning"
siteName = ā€œgreat learning academy"
print(siteName)
• var varA = ā€œSwift"
var varB = 3
print("The course duration of (varA) is (varB) months.")
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Operators
Operators
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
• Assignment Operator
• Arithmetic Operators
• Remainder Operator
• Unary Minus Operator
• Unary Plus Operator
• Compound Assignment Operators
• Comparison Operators
• Ternary Conditional Operator
• Range Operators
• Logical Operators
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Practical
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Optional Types
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Conditional Constructs
Thank You
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited

Swift Tutorial Free For You To Use Brooo

  • 1.
  • 2.
    Agenda Comments Download and Installation 2 Firstprogram 3 Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited 4 Variables 6 Operators 7 Datatypes 5 Introduction 1 Practical 8 Optional Types 9 Conditional Constructs 10
  • 3.
    Proprietary content. ©GreatLearning. All Rights Reserved. Unauthorized use or distribution prohibited Introduction
  • 4.
    Introduction Proprietary content. Ā©GreatLearning. All Rights Reserved. Unauthorized use or distribution prohibited • Swift is a general purpose programming language for developing iOS applications. It is developed by Apple Inc. • It is powerful and intuitive language which is easy to learn. • Swift is a fantastic way to write software, whether it’s for phones, desktops, servers, or anything else that runs code. • Swift follows Objective-C runtime library which allows C, Objective-C, C++ and Swift code to run within one program. • Swift 5.4 is the latest version of Swift. • The compiler is optimized for performance and the language is optimized for development, without compromising on either.
  • 5.
    Introduction Proprietary content. Ā©GreatLearning. All Rights Reserved. Unauthorized use or distribution prohibited Swift defines away large classes of common programming errors by adopting modern programming patterns: • Variables are always initialized before use. • Array indices are checked for out-of-bounds errors. • Integers are checked for overflow. • Optional ensure that nil values are handled explicitly. • Memory is managed automatically. • Error handling allows controlled recovery from unexpected failures. Swift code is compiled and optimized to get the most out of modern hardware. The syntax and standard library have been designed based on the guiding principle that the obvious way to write your code should also perform the best.
  • 6.
    Proprietary content. ©GreatLearning. All Rights Reserved. Unauthorized use or distribution prohibited Download and Installation
  • 7.
    Download and Installation Proprietarycontent. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited There are mainly two things to download when you want to work with Swift in windows: 1. Swift installer for Windows 2. Visual Studio 2019 Community
  • 8.
    Download and Installation Proprietarycontent. Ā©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited Go to swift.org – the official website of Swift and download the windows tool chain of it.
  • 9.
    Download and Installation Proprietarycontent. Ā©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited Go to https://visualstudio.microsoft.com/downloads/ – the official website of Visual studio and download the Community edition of it.
  • 10.
    Download and Installation Proprietarycontent. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited Start the visual studio installer and complete some necessary steps while installing:
  • 11.
    Download and Installation Proprietarycontent. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited This is how the visual studio window will appear when it will be downloaded and installed:
  • 12.
    Download and Installation Proprietarycontent. Ā©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited Tick ā€œDesktop development with C++ā€.
  • 13.
    Download and Installation Proprietarycontent. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
  • 14.
    Download and Installation Proprietarycontent. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited Once all requirements are ticked, we can start Installing our visual studio:
  • 15.
    Download and Installation Proprietarycontent. Ā©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited Now, its time to open swift installer and install swift in our system. In order to make the Windows SDK accessible to Swift, it is necessary to deploy a few files into the Windows SDK. The following will modify your Visual Studio Installation, and as such will require to be run from an (elevated) ā€œAdministratorā€ Because it is installing the files into the Visual Studio image, the files will need to be copied each time Visual Studio is updated.
  • 16.
    Download and Installation Proprietarycontent. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
  • 17.
    Download and Installation Proprietarycontent. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited Copy these with copy command and run it in the command prompt: %SDKROOT%usrshareucrt.modulemap "%UniversalCRTSdkDir%Include%UCRTVersion%ucrtmodule.modulemap" %SDKROOT%usrsharevisualc.modulemap "%VCToolsInstallDir%includemodule.modulemap" %SDKROOT%usrsharevisualc.apinotes "%VCToolsInstallDir%includevisualc.apinotes" %SDKROOT%usrsharewinsdk.modulemap "%UniversalCRTSdkDir%Include%UCRTVersion%ummodule.modulemap"
  • 18.
    Download and Installation Proprietarycontent. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
  • 19.
    Proprietary content. ©GreatLearning. All Rights Reserved. Unauthorized use or distribution prohibited First Program
  • 20.
    First Program Proprietary content.©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited - Environments variables for the Swift compiler: set SWIFTFLAGS=-sdk %SDKROOT% -resource-dir %SDKROOT%usrlibswift -I %SDKROOT%usrlibswift -L %SDKROOT%usrlibswiftwindows - Building a Swift program: swiftc %SWIFTFLAGS% -emit-executable -o First.exe First.swift
  • 21.
    Proprietary content. ©GreatLearning. All Rights Reserved. Unauthorized use or distribution prohibited Comments
  • 22.
    Comments Proprietary content. ©GreatLearning. All Rights Reserved. Unauthorized use or distribution prohibited The first way to write a comment is: // This is a comment. It is not executed. This is a single line comment. You could stack these up like so to allow you to write paragraphs: // This is also a comment. // Over multiple lines. However, there is a better way to write comments that span multiple lines: /* This is also a comment. Over many... many... many lines. */ This is a multi-line comment. The start is denoted by /* and the end is denoted by */.
  • 23.
    Proprietary content. ©GreatLearning. All Rights Reserved. Unauthorized use or distribution prohibited Datatypes
  • 24.
    Datatypes Proprietary content. Ā©GreatLearning. All Rights Reserved. Unauthorized use or distribution prohibited • Int or UInt āˆ’ This is used for whole numbers. Use Int32, Int64 - 32 or 64 bit signed integer whereas UInt32 or UInt64 - 32 or 64 bit unsigned integer variables. • Float āˆ’ This is used to represent a 32-bit floating-point number and numbers with smaller decimal points. For example, 3.14159, 0.1, and -273.158. • Double āˆ’ This is used to represent a 64-bit floating-point number and used when floating-point values must be very large. For example, 3.14159, 0.1, and -273.158. • Bool āˆ’ This represents a Boolean value which is either true or false. • String āˆ’ This is an ordered collection of characters. For example, "Hello, World!" • Character āˆ’ This is a single-character string literal. For example, "C" • Optional āˆ’ This represents a variable that can hold either a value or no value. • Tuples āˆ’ This is used to group multiple values in single Compound Value.
  • 25.
    Proprietary content. ©GreatLearning. All Rights Reserved. Unauthorized use or distribution prohibited Variables
  • 26.
    Variables Proprietary content. Ā©GreatLearning. All Rights Reserved. Unauthorized use or distribution prohibited • var variableName = <initial value> • var siteName:String siteName = ā€œgreat learning" print(siteName) • var siteName = ā€œgreat learning" siteName = ā€œgreat learning academy" print(siteName) • var varA = ā€œSwift" var varB = 3 print("The course duration of (varA) is (varB) months.")
  • 27.
    Proprietary content. ©GreatLearning. All Rights Reserved. Unauthorized use or distribution prohibited Operators
  • 28.
    Operators Proprietary content. Ā©GreatLearning. All Rights Reserved. Unauthorized use or distribution prohibited • Assignment Operator • Arithmetic Operators • Remainder Operator • Unary Minus Operator • Unary Plus Operator • Compound Assignment Operators • Comparison Operators • Ternary Conditional Operator • Range Operators • Logical Operators
  • 29.
    Proprietary content. ©GreatLearning. All Rights Reserved. Unauthorized use or distribution prohibited Practical
  • 30.
    Proprietary content. ©GreatLearning. All Rights Reserved. Unauthorized use or distribution prohibited Optional Types
  • 31.
    Proprietary content. ©GreatLearning. All Rights Reserved. Unauthorized use or distribution prohibited Conditional Constructs
  • 32.
    Thank You Proprietary content.©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited