- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 517 Articles for Swift
![Nitin Aggarwal](https://www.tutorialspoint.com/assets/profiles/558477/profile/60_3034393-1669108333.jpg)
1K+ Views
In this article, we will discuss Swift's comments, why, and how to use them correctly in Swift. Always keep one thing in mind while writing code i.e. The code must be written for people to read and understand as much as possible. Similarly to the Swift language, comments are very useful for making your code more easily understandable to you and other developers. All the comments in the code are completely ignored by the Swift compiler. There are two types of comments in Swift − Single Line Comments Multiline Comments Single Line Comments Syntax Swift allows us to ... Read More
![Nitin Aggarwal](https://www.tutorialspoint.com/assets/profiles/558477/profile/60_3034393-1669108333.jpg)
483 Views
Declaring variables as optional is always recommended and should be the first choice of a developer. You should mark them as optional if they can be invalid (nil or another type). Being developers, we consider it our responsibility to write safe and secure code. To make it possible, Swift provides us with many concepts, and optional is one of them. The optional variable might contain a nil value, so we have to get its value safely. There are a couple of ways to unwrap the value of an optional variable. Let's learn about them. First, we need to understand what ... Read More
![Nitin Aggarwal](https://www.tutorialspoint.com/assets/profiles/558477/profile/60_3034393-1669108333.jpg)
255 Views
Introduction This article will guide you about the usage of Class and what are the benefits of using inheritance in the Swift language. In this article, we will cover the following things − What is a class and what is its usage in Swift? What is inheritance and what are its benefits? What is a Class? In the Swift language, a class is a representation of properties and methods. We use classes to encapsulate properties and methods into a single entity that has the same characteristics. We use classes to store information in variables and constants. A class ... Read More
![Nitin Aggarwal](https://www.tutorialspoint.com/assets/profiles/558477/profile/60_3034393-1669108333.jpg)
423 Views
As an iOS developer, it is imperative to understand the difference between functions and methods in the Swift language. It might be confusing for you to understand the difference between function and method, but you might be thinking they are both the same. That's not true. They have some differences between them. Let's understand it in this article. In the Swift language, simply the methods are used in class, struct, and enum. While functions are defined independently. Basically, you can create a function anywhere in the code without creating a class or structure. Simply, we can say that each ... Read More
![Nitin Aggarwal](https://www.tutorialspoint.com/assets/profiles/558477/profile/60_3034393-1669108333.jpg)
475 Views
In this tutorial, you will get to know about some common design patterns that you should follow while making iOS apps. What are Swift Design Patterns? In Swift, design patterns make the development process easy for developers. A productive and effective work environment can be created by following the design patterns. An iOS design pattern is a set of repeatable methods for creating apps. What are the most common design patterns used in iOS development? Builder Facade MVC Singleton Viper MVVM Adaptor Observer Factory Method Let's talk about some of them to understand how they work − Algorithm ... Read More
![Ankita Saini](https://www.tutorialspoint.com/assets/profiles/489852/profile/60_2374666-1658225115.jpg)
599 Views
In this article, we will learn how to write a swift program to sort the elements of an array in descending order. To sort the elements of an array Swift provides an in-built function named sort(by:). This function takes one argument and then sorts the array according to the condition passed in the by parameter. So to sort the array in descending order we pass > in the by the parameter of the sort(by:) function. Syntax func sort(by:) Here sort(by:) is an instance method. Which will sort the given sequence according to the value of by: parameter. Here ... Read More
![Ankita Saini](https://www.tutorialspoint.com/assets/profiles/489852/profile/60_2374666-1658225115.jpg)
2K+ Views
In this article, we will learn how to write a swift program to sort the elements of an array in ascending order. Here we are going to use the following 2 methods: sort() function without parameter sort(by:) function with parameter To sort the elements of an array Swift provides an in-built function named sort(). This function can work with or without parameters. By default this function sort the array in ascending order. Otherwise, you can pass < in the by a parameter of the sort(by:) function to sort the array in ascending order. Method 1: sort() Function Without ... Read More
![Ankita Saini](https://www.tutorialspoint.com/assets/profiles/489852/profile/60_2374666-1658225115.jpg)
652 Views
In this article, we will learn how to write a swift program to remove all occurrences of an element in an array. So here we use the following methods − Using an inbuilt function Without using an inbuilt function Method 1: Using the removeAll() Function To remove all the occurrences of an element in an array we use a pre-defined function named removeAll(where:). This function removes all the elements from the given sequence that satisfy the given condition. For Example − Array = [2, 3, 5, 67, 2, 87, 2, 68] Element = 2 Output array = [3, 5, 67, ... Read More
![Ankita Saini](https://www.tutorialspoint.com/assets/profiles/489852/profile/60_2374666-1658225115.jpg)
4K+ Views
This article will teach us how to write a swift program to print an array. To print an array, we are using the following methods − Using array name Using for loop Using a while loop Using forEach() method Method 1: Print the array using the array name We can print an array by directly using the name of the array in the print function. Syntax Following is the syntax − print(arrayName) Here we simply pass the name of the array in the print function to display the array. Example The following Swift program shows how to print ... Read More
![Ankita Saini](https://www.tutorialspoint.com/assets/profiles/489852/profile/60_2374666-1658225115.jpg)
1K+ Views
This article will teach us how to write a swift program to print a 2D array. Here we use the following methods − Using array name Using nested for loop Using subscript. Using forEach() method. Method 1: Print the 2D array using the array name We can print a 2D array by directly using the name of the array in the print function. Syntax Following is the syntax − print(arrayName) Here we simply pass the name of the array in the print function to display a 2D array. Example The following Swift program shows how to print ... Read More