Swift Articles

Page 23 of 40

Swift Program to Calculate Average Using Arrays

Ankita Saini
Ankita Saini
Updated on 29-Dec-2022 3K+ 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
Nitin Aggarwal
Updated on 21-Dec-2022 3K+ 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
Nitin Aggarwal
Updated on 21-Dec-2022 1K+ 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
Nitin Aggarwal
Updated on 21-Dec-2022 5K+ 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
Nitin Aggarwal
Updated on 21-Dec-2022 2K+ 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

How to write a Multiple-Line Comment in Swift?

Nitin Aggarwal
Nitin Aggarwal
Updated on 21-Dec-2022 2K+ 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

Explain the usage of Classes and the Benefits of Inheritance in Swift

Nitin Aggarwal
Nitin Aggarwal
Updated on 21-Dec-2022 367 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

Designing patterns used during iOS app development

Nitin Aggarwal
Nitin Aggarwal
Updated on 21-Dec-2022 733 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

Swift Program to Find the Transpose

Ankita Saini
Ankita Saini
Updated on 20-Dec-2022 632 Views

In this article, we will learn how to write a swift program to find the transpose of a matrix. Transpose of a matrix is calculated by interchange the rows of a matrix into columns or columns of a matrix into rows. For example, we have the following matrix: $$\mathrm{X\:=\:\begin{bmatrix} 13, & 59, & 32, & 67 ewline 23, & 56, &89, & 3 ewline 98, & 3, & 32, & 43 ewline 6, & 90, & 43, &23 \end{bmatrix}}$$ So the transpose of matrix X is − $$\mathrm{X^{T}\:=\:\begin{bmatrix} 13, & 23, & 98, & 6 ewline 59, ...

Read More

Swift Program to Sort the Elements of an Array in Descending Order

Ankita Saini
Ankita Saini
Updated on 20-Dec-2022 873 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
Showing 221–230 of 397 articles
« Prev 1 21 22 23 24 25 40 Next »
Advertisements