Found 517 Articles for Swift

How to improve the readability of Swift code?

Nitin Aggarwal
Updated on 09-Dec-2022 12:49:59

135 Views

In this tutorial, you will learn how to improve code readability in the Swift language. You can follow a variety of techniques when writing code. By following these methods, you will be able to write more understandable code for yourself and other developers. Use Comments This is the most important thing we should do. When writing code, we often write logic and calculations. When we start, we have everything in our minds, but after a month, it's definitely difficult to remember everything, especially in large applications. The code is usually commented on single lines. As a result, we are better ... Read More

Explain generics and How to apply method or variable generics in Swift?

Nitin Aggarwal
Updated on 09-Dec-2022 12:45:50

149 Views

In this tutorial, you are about to learn how you can use generics to make your code reusable and flexible in an application. You will see how to create functions and properties that can work with any type with an example. What is generics? Swift allows you to write flexible, reusable code using generics. Generic code can work with any type. You can write code that avoids duplication and expresses its intent in a clear, abstract manner. Generics are one of the most powerful features of Swift, and much of the Swift standard library is built with generic code. You’ve ... Read More

What is the use of the double question mark “??” in Swift?

Nitin Aggarwal
Updated on 09-Dec-2022 12:40:28

2K+ Views

In this tutorial, you will learn the use of double question marks (?) in the Swift language. In Swift, a double question mark (??) is called the "nil−coalescing operator". This operator is basically used to provide a default value in the case of nil. In other words, when a variable is nil and you want to provide a default value in the absence of a value, use this operator. According to Apple documentation The nil-coalescing operator (a ?? b) unwraps an optional a if it contains a value, or returns a default value b if a is nil. The expression ... Read More

What is the difference between class and structure in Swift?

Nitin Aggarwal
Updated on 09-Dec-2022 12:36:25

10K+ Views

This guide will cover what classes and functions there are in the Swift programming language. Also, what are the differences between them? Most of the time, when we write code in a project, we have to deal with classes and structures. It is true that these two features are the most significant in Swift. In a real−time application, whatever you want to write, you need to create a class to assign responsibility. If we already have a class option, we need to understand why and when we should use the structure. Structures are one of the fundamental concepts in the ... Read More

Name Some Advantages of Using Swift

Nitin Aggarwal
Updated on 09-Dec-2022 12:24:03

686 Views

This article will explain to you the advantages of using the Swift programming language. Introduction of the Swift language Swift is a clean and concise programming language that is growing fast and becoming increasingly popular. Swift was initially used for iOS development but has become very popular for many other things like macOS, watchOS, and server-side development. Apple introduced the Swift language as an open-source programming language as a replacement for Objective−C, C, and C++. The Swift language was created in 2014 and released publicly in 2015 by Apple Inc. We can say Swift is a modern programming language like ... Read More

Explain the difference between let and var in Swift

Nitin Aggarwal
Updated on 09-Dec-2022 12:20:52

2K+ Views

This article will explain the difference between let and var in the Swift language. Most of the time, we deal with different data types in any programming language. However, we need to identify values by name. These names are called variables. Like C, Swift uses variables to store and refer to values by an identifying name. Swift also makes extensive use of variables whose values can’t be changed. These are known as constants. They are more powerful than constants in C. Constants are used throughout Swift to make code safer and clearer in intent. This is because you work with ... Read More

Swift Program to Convert Char type variables to Int

Ankita Saini
Updated on 30-Nov-2022 07:20:23

2K+ Views

This tutorial will discuss how to write swift program to convert char type variable to int. Swift support various datatypes and character and integers are one of them. Character represent single-character string like, “2”, “a”, “l”, etc. Whereas Integer represent numeric values like 2, 3, 45, 6, etc. To convert char type variable into Int type we can use any of the following method. Method 1 - Using whole Number Value Property We can convert char type variable into Int type using whole Number Value property. This property will convert character into number value if the character represent a ... Read More

Swift Program to Calculate Cube Sum of First n Natural Numbers

Ankita Saini
Updated on 30-Nov-2022 07:18:25

216 Views

This tutorial will discuss how to write swift program to calculate cube sum of first n natural numbers. Natural numbers are those number which include all the positive number starting from 0 to infinite for example, 1, 2, 3, 4, ……n. Now we find the cube sum of first n natural numbers: 1+23+33+43 = 1 + 8 + 27 + 64 = 100. Below is a demonstration of the same − Input Suppose our given input is − Num = 5 Output The desired output would be − Cube Sum of first 5 numbers are 225. Algorithm Following ... Read More

Swift Program to Calculate the Area of Enneagon

Ankita Saini
Updated on 30-Nov-2022 07:16:34

115 Views

This tutorial will discuss how to write swift program to calculate area of enneagon. A enneagon is a polygon with 9 straight sides and 9 vertices. The sum of all the interior angles is 1260 degree. The total amount of space enclosed inside the nine sides of the enneagon is known as the area of the enneagon. Formula Following is the formula of the area of the enneagon − Area = ((x2*9) / 4*tan (20°)) ∼= (6.18 * x2) Here, x is the side of the enneagon. Below is a demonstration of the same − Input Suppose our ... Read More

Swift Program to Calculate Area and Perimeter of Equilateral Triangle

Ankita Saini
Updated on 30-Nov-2022 07:14:57

364 Views

This tutorial will discuss how to write swift program to calculate area and perimeter of equilateral triangle A triangle whose all sides and angles are equal is known as the equilateral triangle. Each angle of equilateral triangle is 60 degrees. It is also known as 3-side polygon. Area of Equilateral Triangle The amount of space occupied between the three lines of the triangle is known as the area of the equilateral triangle. Formula Following is the formula − Area = √3x2/ 4 Here x is the side of the equilateral triangle. Below is a demonstration of the ... Read More

Advertisements