Nitin Aggarwal has Published 155 Articles

How can I use Timer (formerly NSTimer) in Swift?

Nitin Aggarwal

Nitin Aggarwal

Updated on 28-Feb-2023 12:39:44

2K+ Views

You can use the Timer class in Swift to create a timer that can execute a method repeatedly at a specified time interval. You can implement the timer to solve different problems. You can schedule repeatable and non-repeatable timers in Swift. Timers in Swift can be used to perform a ... Read More

How can I make a weak protocol reference in 'pure' Swift (without @objc)?

Nitin Aggarwal

Nitin Aggarwal

Updated on 28-Feb-2023 12:33:31

1K+ Views

In Swift, you can make a weak protocol reference by using the weak keyword when declaring the variable or property that holds the reference to the protocol. The weak reference helps you to avoid the retain cycle creation. What is a weak protocol reference? A weak protocol reference in Swift ... Read More

How base-class is defined in Swift?

Nitin Aggarwal

Nitin Aggarwal

Updated on 28-Feb-2023 12:31:47

338 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 ... Read More

Generate random alphanumeric string in Swift

Nitin Aggarwal

Nitin Aggarwal

Updated on 28-Feb-2023 12:30:01

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 ... Read More

Explain some common features of Protocol & Superclass in Swift

Nitin Aggarwal

Nitin Aggarwal

Updated on 28-Feb-2023 12:25:52

359 Views

In Swift, there are two different concepts i.e. protocols and superclasses are used to build the application by writing reusable and flexible code. They both are different concepts but somehow they have some common features. You can define the protocol with methods and properties to achieve any particular feature. In ... Read More

How to create a button programmatically?

Nitin Aggarwal

Nitin Aggarwal

Updated on 28-Feb-2023 12:21:47

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 ... Read More

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

Nitin Aggarwal

Nitin Aggarwal

Updated on 28-Feb-2023 12:20:20

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 ... Read More

Changing the text of UIButton programmatically in Swift

Nitin Aggarwal

Nitin Aggarwal

Updated on 28-Feb-2023 12:18:50

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 ... Read More

Programmatically go back to the previous ViewController in Swift

Nitin Aggarwal

Nitin Aggarwal

Updated on 28-Feb-2023 12:15:25

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 ... Read More

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

Nitin Aggarwal

Nitin Aggarwal

Updated on 28-Feb-2023 12:14:04

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 ... Read More

Advertisements