Found 517 Articles for Swift

Swift Program to Display Upper Triangular Matrix

Ankita Saini
Updated on 29-Dec-2022 17:23:06

120 Views

In this article, we will learn how to write a swift program to display upper triangular matrix. Upper triangular matrix is a matrix in which all the elements below the primary diagonal are zero. As shown in the below image − $$\mathrm{\begin{bmatrix} 1 & 4 & 6 & 7 & 8 & 8ewline 0 & 5 & 6 & 8 & 9 & 9ewline 0 & 0 & 6 & 7 & 8 & 3ewline 0 & 0 & 0 & 2 & 1 & 1ewline 0 & 0 & 0 & 0 & 2 & 1ewline 0 & 0 ... Read More

Swift Program to Display Lower Triangular Matrix

Ankita Saini
Updated on 29-Dec-2022 17:01:30

149 Views

In this article, we will learn how to write a swift program to display lower triangular matrix. Lower triangular matrix is a matrix in which all the elements above primary diagonal are zero. As shown in the below image: $$\mathrm{\begin{bmatrix} 1 & 0 & 0 & 0 & 0 & 0ewline 3 & 5 & 0 & 0 & 0 & 0ewline 1 & 4 & 6 & 0 & 0 & 0ewline 1 & 2 & 2 & 2 & 0 & 0ewline 4 & 5 & 6 & 1 & 2 & 0ewline 1 & 1 & 1 ... Read More

Swift Program to Compute the Sum of Diagonals of a Matrix

Ankita Saini
Updated on 29-Dec-2022 17:23:41

523 Views

In this article, we will learn how to write a swift program to compute the sum of diagonals of a matrix. Every matrix has two diagonals which are known as primary and secondary diagonals. For example, we have the following 5x5 square matrix − 2 3 4 5 6 4 6 7 8 9 1 1 1 3 4 4 0 4 0 4 0 0 1 1 1 So the primary diagonal is formed by using elements 2, 6, 1, 0, 1 and the secondary diagonal is formed by using elements 6, 8, 1, 0, 0. Hence the ... Read More

Swift Program to Check Whether Two Matrices Are Equal or Not

Ankita Saini
Updated on 29-Dec-2022 17:24:11

118 Views

In this article, we will learn how to write a swift program to check whether two matrices are equal or not. Here, we create two matrices, and using the not equal to the operator (!=), we check whether all the elements of both matrices are equal or not. Algorithm Step 1 − Create a function. Step 2 − Use nested for loop to iterate through each row and column. Step 3 − Check if the element of matrix1 is not equal to matrix2. If the condition is true, then return 0, otherwise, return 1. Step 4 − Create two ... Read More

Swift Program to Calculate Standard Deviation

Ankita Saini
Updated on 29-Dec-2022 17:24:40

424 Views

In this article, we will learn how to write a swift program to calculate standard deviation. Standard deviation is a measure, which will represent how much variation from the mean exists, or we can say that it is used to calculate the extent to which the values are differ from the average. $$\mathrm{\sigma\:=\:\sqrt{{\frac{1}{N}}\sum_{i=1}^N\:(X_i-\mu)^2}}$$ The mathematical formula of standard deviation is- σ = standard deviation N = total number of elements Xi = ith element \mu = Mean of the given elements Therefore, in this article, we calculate the standard deviation of the given array by using the ... Read More

Swift Program to Calculate Average Using Arrays

Ankita Saini
Updated on 29-Dec-2022 15:53:37

2K+ Views

In this article, we will learn how to write a swift program to calculate averages using an array. Average is defined as the ratio of the sum of the elements present in the given sequence to the total number of elements available in the given sequence. The general formula of average is − Average = (p1+p2+p3+..+pn)/n Here we use the following methods to calculate the average using array − Using pre−define functions Without using predefine functions Method 1: Using Pre-Define Functions To find the average of the given array, we use reduce() method to find the sum ... Read More

What is the difference between Array and NSArray?

Nitin Aggarwal
Updated on 21-Dec-2022 16:27:20

2K+ Views

Since Array and NSArray are both core constructs in iOS development, we sometimes forget just how different they are. Here are some major differences between the two constructs that you should know about. Array is a struct, therefore it is a value type in Swift. NSArray is an immutable Objective C class, therefore it is a reference type in Swift. Array is a Swift construct, and generic struct, which means that it can be an array of any specific type (Int, String, etc.). [T] is syntactic sugar for Array. NSArray is an Objective-C construct that can hold any Objective-C ... Read More

What is an attribute in Swift?

Nitin Aggarwal
Updated on 21-Dec-2022 16:24:40

790 Views

Throughout this article, you will learn what an attribute in Swift is and how to use it with code examples. Swift Attributes Swift makes it possible to provide some additional info about the declaration or type. We have two types of attributes that can be used in Swift language. Declaration Attributes Type Attributes Syntax You can apply an attribute by using the symbol @ followed by the attribute name, as shown below − @attribute name @attribute name(attribute arguments) Explanation We can provide arguments in declaration attributes to define the declaration. These arguments can be provided in parentheses ... Read More

What is a Delegate in Swift?

Nitin Aggarwal
Updated on 21-Dec-2022 15:25:33

3K+ Views

In this article, you will learn about what Delegate is and how it works. What is Delegation? As the name implies, delegation gives control to other objects. To make it happen, the delegate object has to be assigned to control other objects. In iOS apps, the UIApplicaitonDelegate is an example. UIApplicationDelegate allows you to modify iOS behavior, such as receiving push notifications, opening URLs, and launching apps. A delegation pattern ensures the functionality that needs to be delegated is provided. Delegate patterns enable objects to communicate back to their owners decoupled from their code. It is much easier to ... Read More

What are the common execution iOS Application Lifecycle?

Nitin Aggarwal
Updated on 21-Dec-2022 15:20:46

893 Views

In this article, you will learn about the different execution states of an iOS application. Based on the current state, you can decide what task you want to perform. There are different states that an app might have. The iPhone operating system (iOS) provides us with different five states of an application like the following − Not running Inactive Active Background Suspended An iOS application runs in several states, known as states of the application life cycle. App life cycles are crucial for iOS developers, as they help them understand how their apps behave. The following states are ... Read More

Advertisements