Found 517 Articles for Swift

How to add constraints programmatically using Swift

Nitin Aggarwal
Updated on 02-Jan-2023 12:57:00

10K+ Views

The goal of this article is to explain how you can add constraints programmatically in the Swift language. To programmatically add constraints in Swift, you can use the NSLayoutConstraint class to define the constraints you want to add. Concepts That Will Be Used To Add Constraints Are The Following The translatesAutoresizingMaskIntoConstraints is a property of UIView in the UIKit framework. It is a boolean value that determines whether the view's autoresizingMask properties are translated into Auto Layout constraints. When translatesAutoresizingMaskIntoConstraints is set to NO, the autoresizingMask is ignored and the view is resized accrding to any constraints that have been ... Read More

How does one generate a random number in Apple's Swift language?

Nitin Aggarwal
Updated on 02-Jan-2023 12:51:25

302 Views

This article will explain to you how to generate random numbers in the Swift language. There are some common situations when you need to generate random values in your iOS apps such as Simulating dice rolls. Shuffling playing cards. Create a unique ID for a user. The random value from collection type. In Swift 4.2, there are new, simple and secure ways to generate random values. Before that, there was a random function written in the C language. Today, you'll learn about the random() function that takes a range of values and as an output, it returns a ... Read More

How do I get a reference to the app delegate in Swift?

Nitin Aggarwal
Updated on 02-Jan-2023 12:39:40

2K+ Views

You should know what an AppDelegate is in Swift before jumping to how to get a reference to it. AppDelegate In an iOS application, the app delegate is the entry point for the application. Throughout the application, this object has been created once by iOS and is accessible in shared mode. It's responsible for handling key events and tasks related to your app's lifecycle, such as responding to system notifications and managing the app's window and view hierarchy. Where it is Defined? The app delegate class is typically defined in the AppDelegate.swift file of your Xcode project. It should conform ... Read More

Get the Nth character of a string in the Swift programming language

Nitin Aggarwal
Updated on 02-Jan-2023 12:34:42

1K+ Views

In this article, you will learn how to obtain the Nth character of a string. You will use the index() method to get the Nth character of a string. This method will give you the position index of the given string. How to use the Index() Method? Let's look at an example of how to use the index() method Algorithm Step 1 − Prepare an input string. Step 2 − Call the index() method with the target offset. Step 3 − Use the position index as a subscript to the input string. Step 4 − Store the Nth character. Example ... Read More

Swift Program to Print Boundary Elements of a Matrix

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

199 Views

In this article, we will learn how to write a swift program to print boundary elements of a matrix. Boundary elements of a matrix are those elements that are present on the boundary of the matrix that are elements in the first row, last row, first column, and last column. For example − Given Matrix: 2 4 5 6 7 8 4 5 6 7 3 2 3 4 5 6 2 1 1 1 1 1 1 1 3 4 3 4 3 4 2 2 2 2 2 2 Boundary elements are: 2 4 5 6 ... Read More

Swift Program to Interchange the Diagonals of a Matrix

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

145 Views

In this article, we will learn how to write a swift program to interchange the diagonals. Therefore, to interchange the diagonals we need to swap the elements of primary diagonal with the elements of secondary diagonal of the given matrix. For example − Original matrix: 2 4 5 6 3 4 6 2 6 7 7 2 1 1 1 1 So after swapping diagonals we get: 6 4 5 2 3 6 4 2 6 7 7 2 1 1 1 1 Algorithm Step 1 − Create a function. Step 2 − Run a for loop ... Read More

Swift Program to Interchange Elements of First and Last Rows of a Matrix

Ankita Saini
Updated on 29-Dec-2022 17:21:05

178 Views

In this article, we will learn how to write a swift program to interchange the elements of first and last in a matrix across rows. Therefore, to interchange the elements we need to swap the elements of the first row with the elements of the last row of the given matrix. For example − Original matrix: 2 4 5 6 3 4 6 2 6 7 7 2 1 1 1 1 So after swapping the first and last rows we get: 1 1 1 1 3 4 6 2 6 7 7 2 2 4 5 6 ... Read More

Swift Program to Interchange Elements of First and Last Columns of Matrix

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

198 Views

In this article, we will learn how to write a swift program to interchange the elements of first and last in a matrix across columns. Therefore, to interchange the elements we need to swap the elements of the first column with the elements of the last column of the given matrix. For example − Original matrix: 2 4 5 6 3 4 6 2 6 7 7 2 1 1 1 1 So after swapping the first and last column we get: 6 4 5 2 2 4 6 3 2 7 7 6 1 1 1 1 ... Read More

Swift Program to Find the Trace and Normal of a given Matrix

Ankita Saini
Updated on 29-Dec-2022 17:21:58

82 Views

In this article, we will learn how to write a swift program to find trace and normal of a given matrix. Calculating the Trace of a given Matrix Trace is known as the sum of primary diagonal elements of the given square matrix. For example, we have a 3x3 square matrix − 2 3 4 3 4 6 1 3 2 So the primary diagonal elements are 2, 4 and 2. Hence the trace of the given 3x3 matrix is 2+4+2 = 8. Algorithm Step 1 − Define the size of the matrix. Step 2 − Create a ... Read More

Swift Program to Find the Sum of the Boundary Elements of a Matrix

Ankita Saini
Updated on 29-Dec-2022 17:22:34

93 Views

In this article, we will learn how to write a swift program to find the sum of the boundary elements of a matrix. Boundary elements of a matrix are those elements that are present on the boundary of the matrix that are elements in the first row, last row, first column, and last column. For example − Given Matrix: 2 4 5 6 7 8 4 5 6 7 3 2 3 4 5 6 2 1 1 1 1 1 1 1 3 4 3 4 3 4 2 2 2 2 2 2 Boundary elements are: ... Read More

Advertisements