Nitin Aggarwal

Nitin Aggarwal

132 Articles Published

Articles by Nitin Aggarwal

Page 10 of 14

How base-class is defined in Swift?

Nitin Aggarwal
Nitin Aggarwal
Updated on 28-Feb-2023 395 Views

In Swift, you can define a base class using the class keyword. The base class can be used to implement common properties using a single class. You can define the properties and methods in a class like the one below − class MyBaseClass { // properties and methods go here } A subclass is also defined by the class keyword. In a similar way, you can define the properties and methods in the class. To make it a subclass, you have to mention the parent class followed by the parent class name after the colon like ...

Read More

Generate random alphanumeric string in Swift

Nitin Aggarwal
Nitin Aggarwal
Updated on 28-Feb-2023 3K+ Views

In this article, you will learn various ways to generate random alphanumeric strings in the Swift language. Here we are going to use the following 3 methods to generate a random alphanumeric string in swift − Using the RandomNumberGenerator protocol Using the Random() function Using higher-order functions Using the RandomNumberGenerator protocol Swift 5 comes with a random() function that is added to the Foundation framework. We will use the RandomNumberGenerator protocol as the random() function is a part of this protocol.Example The following example demonstrates on how to use the random() function to generate a random alphanumeric ...

Read More

How to create a button programmatically?

Nitin Aggarwal
Nitin Aggarwal
Updated on 28-Feb-2023 2K+ Views

In this article, you will learn about how to create a button prograticamtilly in the Swift language. There are different ways to create a button object programmatically in iOS. Let's explore some of them with an example. We will see the following ways to create a button − Step 1 − In this step, we will create a button object and customize it later when required. Step 2 − In this step, we will create a button object using a lazy keyword. Step 3 − In this step, we will create a button object and set the frame later. ...

Read More

How can I make a button have a rounded border in Swift?

Nitin Aggarwal
Nitin Aggarwal
Updated on 28-Feb-2023 7K+ Views

In Swift, you can use the layer property of a UIButton to set the corner radius of its border. You can use the layer (CALayer) property to apply the border width and color to the button. Also, the same property provides access to the cornerRadius property to make the button rounded. We will use the following steps to make a button rounded with a border Step 1 − In this step, create a button object with basic customization. Step 2 − In this step, add a border and corner radius to the button. Step 3 − In this step, make ...

Read More

Changing the text of UIButton programmatically in Swift

Nitin Aggarwal
Nitin Aggarwal
Updated on 28-Feb-2023 8K+ Views

To change the text of a UIButton in Swift, you can use the setTitle() method of the button. This method takes an argument to set the button title for a particular state. Generally, we used the normal button state. We will change the text of the button programmatically by following the below steps − Step 1 − In this step, we will create two buttons (login and T&C) and add basic customization. Step 2 − In this step, we will change the text of the login button. Step 3 − In this step, we will change the text of the ...

Read More

Programmatically go back to the previous ViewController in Swift

Nitin Aggarwal
Nitin Aggarwal
Updated on 28-Feb-2023 6K+ Views

This article explains how to go back from a view controller programmatically using Swift language. You will see an example of using the popViewController method to go back to the previous controller. What is ViewController in Swift? In Swift, a UIViewController manages the interaction between the user interface and the logic data. It is responsible for handling user interactions with the user interface. The class is part of the UIKit framework and provides some functions and properties along with a life cycle. This class is the most common class used in iOS development. To go back to a previous view ...

Read More

How to hide the keyboard in Swift by pressing the return key?

Nitin Aggarwal
Nitin Aggarwal
Updated on 28-Feb-2023 3K+ Views

In this article, you will learn about how you can hide the keyboard while editing text in the UITextField. In this example, you will hide the keyboard by pressing the return button on the keyboard. In the Swift language, UITextField class provides us with some delegate methods. They called on different actions or events. We will implement one of the delegate methods to hide the keyboard. Also, you will see how to change the return type if required. In this example, we will hide the keyboard in UITextField to enter an email address by following the below steps − ...

Read More

How to change the font of UIButton with Swift?

Nitin Aggarwal
Nitin Aggarwal
Updated on 28-Feb-2023 11K+ Views

In Swift, this is very easy to change the font of a button. You can use the titleLabel property of the button which is of type UILabel class. This property provides another property called font to apply the desired font. Let’s see some examples of changing the font. We will follow the below steps to change the font of a button − Step 1 − Initially, we will do the basic setup with button creation and customization. Step 2 − In this step, we will change the system font with size and weight. Step 3 − In this ...

Read More

What are the new features in Swift 4.0?

Nitin Aggarwal
Nitin Aggarwal
Updated on 05-Jan-2023 516 Views

In this tutorial, you are going to learn what changes have been released in Swift 4. Every time, Apple releases major versions with lots of improvements and additions to APIs. The new features introduced in Swift 4.0 include improved key paths for key-value coding, encoding and decoding, multi-line string literals, Strings are collections, improved dictionary functionality, one-sided ranges, and many other code enhancements. Encoding & Decoding In Swift 4.0, Apple introduced the Codable protocol to make encoding and decoding easy for developers. You can implement serialization and deserialization in your code using this protocol. You can encode and decode your ...

Read More

Precision String Format Specifier In Swift

Nitin Aggarwal
Nitin Aggarwal
Updated on 03-Jan-2023 2K+ Views

It is sometimes necessary to format strings in a custom format in order to use them in an application. For example, you can format product prices, decimal-point numbers, etc. In Swift, you can use precision specifiers to specify the number of decimal places or the number of characters to be displayed in a string. Example 1 To specify the number of decimal places for a floating-point number, you can use the %.nf format specifier, where n is the number of decimal places., import Foundation let productPrice = 300.3456789 let formattedPrice = String(format: "%.2f", productPrice) print("The formatted price is: ", formattedPrice) ...

Read More
Showing 91–100 of 132 articles
« Prev 1 8 9 10 11 12 14 Next »
Advertisements