Swift Tutorial
Swift Tutorial
Swift Tutorial
Agenda
1 Introduction 7 Operators
5 Datatypes
6 Variables
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Introduction
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Introduction
• Swift is a general purpose programming language for developing iOS applications. It is developed by Apple
Inc.
• 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.
• The compiler is optimized for performance and the language is optimized for development, without
compromising on either.
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Introduction
Swift defines away large classes of common programming errors by adopting modern programming patterns:
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
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Download and Installation
There are mainly two things to download when you want to work with Swift in windows:
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Download and Installation
Go to swift.org – the official website of Swift and download the windows tool chain of it.
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Download and Installation
Go to https://visualstudio.microsoft.com/downloads/ – the official website of Visual studio and download the
Community edition of it.
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Download and Installation
Start the visual studio installer and complete some necessary steps while installing:
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Download and Installation
This is how the visual studio window will appear when it will be downloaded and installed:
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Download and Installation
Tick “Desktop development with C++”.
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
Download and Installation
Once all requirements are ticked, we can start Installing our visual studio:
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Download and Installation
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.
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
Download and Installation
Copy these with copy command and run it in the command prompt:
%SDKROOT%\usr\share\ucrt.modulemap "%UniversalCRTSdkDir%\Include\%UCRTVersion%\ucrt\module.modulemap"
%SDKROOT%\usr\share\visualc.modulemap "%VCToolsInstallDir%\include\module.modulemap"
%SDKROOT%\usr\share\visualc.apinotes "%VCToolsInstallDir%\include\visualc.apinotes"
%SDKROOT%\usr\share\winsdk.modulemap "%UniversalCRTSdkDir%\Include\%UCRTVersion%\um\module.modulemap"
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
First Program
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
First Program
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Comments
The first way to write a comment is:
This is a single line comment. You could stack these up like so to allow you to write paragraphs:
However, there is a better way to write comments that span multiple 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
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Datatypes
• 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.
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Variables
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Variables
• var siteName:String
siteName = “great learning"
print(siteName)
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Operators
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Operators
• 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
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Thank You
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited