Difference Between Active Attack and Passive Attack

Kiran Kumar Panigrahi
Updated on 20-Dec-2022 11:44:29

16K+ Views

Active and Passive Attacks are security attacks that jeopardize the security of a system. Security attacks are basically the unauthorized actions that that are taken to destroy, change, or steal the sensitive information and data from the system. In an Active attack, an attacker tries to modify the content of the messages. On the other hand, in a Passive attack, an attacker observes the messages, copy them and may use them for malicious purposes. Read this article to find out more about Active and Passive attacks and how they are different from each other. Let's start with some basics of ... Read More

Sort Elements of an Array in Descending Order Using Swift

Ankita Saini
Updated on 20-Dec-2022 11:27:29

789 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

Sort Elements of an Array in Ascending Order in Swift

Ankita Saini
Updated on 20-Dec-2022 11:26:00

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

Remove All Occurrences of an Element in an Array in Swift

Ankita Saini
Updated on 20-Dec-2022 11:21:29

858 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

Print an Array in Swift

Ankita Saini
Updated on 20-Dec-2022 11:17:05

5K+ 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

Print a 2D Array in Swift

Ankita Saini
Updated on 20-Dec-2022 11:04:39

2K+ 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

Find Common Array Elements in Swift

Ankita Saini
Updated on 20-Dec-2022 10:56:51

2K+ Views

This article will teach us how to write a swift program to find common array elements. So here we use the following methods − Using the filter method Using sets But before moving to the methods, we first understand common elements with the help of an example. Suppose we have two arrays − Arr1 = [2, 4, 6, 89, 78] Arr2 = [56, 88, 32, 4, 99, 89] So the common elements between two arrays are [4, 89]. Because they are available in Arr1 and Arr2. Method 1: Using filter(_:) Method To find common elements between two arrays ... Read More

Count Elements of an Array in Swift

Ankita Saini
Updated on 20-Dec-2022 10:53:35

311 Views

In this article, we will learn how to write a swift program to count the elements of an array. To count the elements of an array swift provide a count property. This property will return the total number of elements present in the specified array. For example − Arr = [3, 5, 6, 4, 6] so the count will return 5. Syntax var count: Int{get} Or you can also write it as − arrayName.count Here count is the property of the array to count the total elements present inside the array. To use this property we ... Read More

Check If Two Arrays Are Equal in Swift

Ankita Saini
Updated on 20-Dec-2022 10:50:47

4K+ Views

In this article, we will learn how to write a swift program to check whether two arrays are equal. To check if two arrays are equal to not either, we are going to use the following two methods − using == operator elementsEqual(_:) method. Both method and operator return true if both the given array has the same elements. Otherwise, they will return false. For example, arr1 = [2, 3, 4, 5] and arr2 = [2, 3, 4, 5] both arrays are equal so both the method and operator will return true. arr1 = [2, 3, 4, ... Read More

Check If an Array is Empty in Swift

Ankita Saini
Updated on 20-Dec-2022 10:38:52

4K+ Views

In this article, we will learn how to write a swift program to check if an array is empty. Here we use two methods: Using isEmpty property Using conditional statements Method 1: Using isEmpty Property To check if an array is empty Swift provides an isEmpty property. This property will return true if the given array is empty or return false if the given array is not empty. For example Arr = [3, 5, 6, 4, 6] so isEmpty property will return false. Syntax var isEmpty: Bool{get} Or you can also write it as − arrayName.isEmpty ... Read More

Advertisements