Swift Tutorial

Welcome to Swift Tutorial. In this series of Swift Tutorials, you will learn all the basics of Swift programming language with detailed examples.

Introduction to Swift

  • Swift is a new programming language developed by Apple Inc.
  • Swift is used to develop applications for iOS and OS X.

Pre-requisites for Swift Tutorial

This Swift Tutorial is targeted for beginners. So, every topic shall be explained in detail. You will find it better if you know basic programming concepts or any other programming language.

Swift Tutorials

In this Swift Tutorial series, we shall go through the following topics.


Get Started

Create a Swift Project (Command Line Tool) in Xcode


Swift Basic Tutorials

These basic Swift Tutorials gets you introduced with the datatypes available in Swift, how to declare variables, constants, etc, what are the keywords available in swift, and operators like logical, arithmetic, boolean, etc.

Swift Hello World Program

Swift Comments

Swift Tuples

Swift Keywords

Variables

How to create an Integer variable in Swift?

How to create a String variable in Swift?

How to get Type of variable in Swift?


Swift Datatypes

The following Swift Tutorials deal with each of the datatype in Swift separately with examples.

Swift Boolean


Swift Operators

The following Swift Tutorials deal with each of the operator in Swift separately with examples.

  1. Swift Operators
  2. Swift Ternary Operator
  3. Swift AND Operator
  4. Swift OR Operator
  5. Swift NOT Operator

Swift Decision Making Tutorials

The decision making statements are those that execute a block of statements based on the evaluation of an expression (or condition).

Swift if

Swift if else

Swift switch

Swift Ternary Operator


Swift Loops Tutorials

Looping statements help to execute a set of statements repeatedly based on the evaluation of a condition. Also, there are loop control statements like break and continue to break a loop abruptly and continue with the other statements or skip the execution of statements for an iteration.

Swift for loop

Swift while loop

Swift repeat while loop

Swift continue

Swift break

Swift forEach

Swift forEach – break


Swift Keywords

Swift defer

Swift guard

Swift let


Swift Input-Output

Swift – Read User Input from Console

Swift – Read Number from Console

Swift – Print to Console Output


Swift Printing

Swift – Print without New Line

Swift – Print Multiple Strings with a Specific Separator


Swift Strings Tutorials

Strings are the basic data types that one uses for most of the real-time applications. Following series of Swift Tutorials help you on how to work with Strings in Swift, how to find the length of a string, how to check if two strings are equal, how to convert a string to integer or vice-versa, and other useful string operations.

Swift String Tutorials


Swift Array Tutorials

Arrays store like kind of elements in a sequential manner and can be accessed using a single variable name and of-course the index. Following Swift Tutorials deal with how to work with Arrays in Swift, starting from initialization and proceeding with different operations like printing, checking, appending, removing elements from the array.

Swift Array Tutorials


Swift Set Tutorials

Sets are collection of items that are stored not necessarily in sequential manner.

Swift Set Tutorials


Swift Dictionary Tutorials

Swift Dictionary Tutorials


Other Useful Swift Tutorials

Swift Enum

Swift Structures


Swift Error Handling

Swift error: return from initializer without initializing all stored properties

Swift – struct error: missing argument labels in call


Swift Programs

Mathematical Programs

  1. Swift – Calculate the factorial of a number
  2. Swift – Swap two numbers
  3. Swift – Generate a random number
  4. Swift – Check if a number is a palindrome
  5. Swift – Find the Greatest Common Divisor (GCD)
  6. Swift – Find the Least Common Multiple (LCM)
  7. Swift – Check Prime Number
  8. Swift – Generate a Fibonacci Series up to a Given Number
  9. Swift – Calculate the Power of a Number using Recursion
  10. Swift – Count the Number of Digits in an Integer
  11. Swift – Reverse an Integer
  12. Swift – Check Armstrong Number
  13. Swift – Find the Sum of Digits of a Number
  14. Swift – Check Perfect Number
  15. Swift – Calculate Simple Interest
  16. Swift – Calculate Compound Interest
  17. Swift – Check Strong Number

Recursion-Based Programs

  1. Swift – Calculate Factorial using Recursion
  2. Swift – Generate Nth Fibonacci Number using Recursion
  3. Swift – Tower of Hanoi
  4. Swift – Find Greatest Common Divisor (GCD) using Recursion
  5. Swift – Reverse String using Recursion
  6. Swift – Count Number of Digits in an Integer using Recursion
  7. Swift – Find Sum of Digits of a Number using Recursion
  8. Swift – Generate all Subsets of a Set using Recursion
  9. Swift – Solve the N-Queens Problem using Recursion
  10. Swift – Find Permutations of a String using Recursion

Logical and Algorithmic Programs

  1. Swift – Check Leap Year
  2. Swift – Print Multiplication Table of a Number
  3. Swift – Find the Largest of Three Numbers
  4. Swift – Implement a Basic Calculator (Add, Subtract, Multiply, Divide)
  5. Swift – Generate Pascal’s triangle
  6. Swift – Count the number of prime numbers in a range
  7. Swift – Check if two numbers are co-prime
  8. Swift – Implement a binary search algorithm
  9. Swift – Find the square root of a number without using a library

Data Structure Programs

  1. Swift – Implement a stack (push, pop, peek)
  2. Swift – Implement a queue (enqueue, dequeue)
  3. Check if parentheses are balanced in an expression
  4. Find the maximum element in a stack
  5. Implement a linked list (add, delete, traverse)
  6. Reverse a linked list
  7. Implement a binary tree (add, search, traverse)
  8. Implement depth-first and breadth-first search
  9. Check if a binary tree is a binary search tree
  10. Find the height of a binary tree

File Handling

  1. Read and write to a file
  2. Count the number of lines, words, and characters in a file
  3. Append data to a file
  4. Find the largest and smallest word in a file
  5. Copy content from one file to another
  6. Check if a file exists
  7. Encrypt and decrypt a file
  8. Replace a specific word in a file
  9. Merge two files into one
  10. Count the frequency of a word in a file

Pattern Printing

  1. Print a pyramid pattern of numbers
  2. Print a right-angled triangle pattern of stars
  3. Print an inverted pyramid
  4. Print Pascal’s triangle
  5. Print a diamond pattern
  6. Print Floyd’s triangle
  7. Print a checkerboard pattern
  8. Print an alphabet pattern (A, B, C…)
  9. Print a hollow square or rectangle
  10. Print a zig-zag pattern

Date and Time Programs

  1. Swift – Get Current Date
  2. Swift – Get Current Time
  3. Swift – Get Difference between Two Dates
  4. Swift – Find Day of Week for a given Date
  5. Swift – Add Days to a Given Date
  6. Swift – Check if a Date is Valid
  7. Swift – Convert Timestamp to Human-readable Format
  8. Swift – Find number of Days in a given Month
  9. Swift – Calculate Age from a Given Birthdate
  10. Swift – Format Date into Different Styles
  11. Swift – Find Next Occurrence of a given Weekday

Networking

  1. Implement a simple client-server program
  2. Send a file over a network
  3. Create a chat application
  4. Fetch data from a URL
  5. Ping a website
  6. Check if a port is open
  7. Implement a basic HTTP server
  8. Resolve DNS names to IP addresses
  9. Monitor network usage
  10. Simulate a simple REST API client