Found 517 Articles for Swift

How do I make an attributed string using Swift?

Nitin Aggarwal
Updated on 07-Sep-2023 09:10:50

218 Views

This article will explain how you can make an attributed string in the Swift language. What are the steps to apply different attributes to a string in Swift? In Swift, we use the NSAttributedString class to make an attributed string. In Swift, NSAttributedString is a class used to create and manage attributed strings. An attributed string is a string that has additional attributes, such as text color, font, and style, applied to parts of the string. This article will show different use cases for an attributed string. Basic Setup import UIKit class TestController: UIViewController { private ... Read More

How do I change the font size of a UILabel in Swift?

Nitin Aggarwal
Updated on 07-Sep-2023 08:58:53

613 Views

You can change the font size of a UILabel in Swift by setting the font property of the UILabel to a UIFont object with the desired point size. Here is the code for the basic setup import UIKit class TestController: UIViewController { private let messageLabel = UILabel() override func viewDidLoad() { super.viewDidLoad() initialSetup() } ... Read More

How do I add 1 day to an NSDate?

Nitin Aggarwal
Updated on 07-Sep-2023 08:55:29

58 Views

In this article, you will learn how to add the number of days to a date in the Swift language. Many times, you might need to modify the date by changing some number of days, weeks, months, etc. Swift provides an in-built concept for adding a component to date. Let's see some examples. Let's take a brief look at a few of the common concepts that will be used in these examples. Calendar Class The Calendar class in Swift is a class that represents a calendar, which is a system for organizing dates. It is used to perform calendar-related calculations, ... Read More

Getting a "This application is modifying the autolayout engine from a background thread" error?

Nitin Aggarwal
Updated on 07-Sep-2023 08:50:34

53 Views

In iOS development, this error frequently occurs while working on user interfaces. Also, you can reduce the chances of coming across this error if you write code carefully. Let's understand what this error is all about. It will help you to understand the reason behind this error if you read the error statement. The error "This application is modifying the autolayout engine from a background thread" is caused when an application attempts to make changes to the user interface from a background thread, which is not allowed in iOS development. Autolayout is a system for defining the layout of user ... Read More

Get the class name of an object as a string in Swift

Nitin Aggarwal
Updated on 07-Sep-2023 08:49:13

631 Views

This article will explain to you how to get the name of the class of an object in the Swift language. Swift provides us with a function called type(of:) to get the type of a value or the class name of an object. You can use the type(of:) function to find the dynamic type of a value, particularly when the dynamic type is different from the static type. The static type of a value is the known, compile-time type of the value. The dynamic type of a value is the value’s actual type at run-time, which can be a subtype ... Read More

Generate a UUID on iOS from Swift

Nitin Aggarwal
Updated on 06-Sep-2023 18:14:04

406 Views

This article will explain to you what is the UUID in iOS and how to generate it in the Swift language. You will see some practical situations in which UUID is useful in the iOS application. What is UUID? A universally unique identifier (UUID) is a string of characters that is guaranteed to be unique across all devices and at all times. UUIDs are often used to uniquely identify resources, such as database records or files. In iOS, UUIDs can be used for a variety of purposes. Some common use cases for UUIDs in iOS include − Identifying app-specific ... Read More

Swift program to generate an OTP

Ankita Saini
Updated on 15-Jun-2023 16:16:30

252 Views

An OTP is known as a one-time password. It is an automatically generated random numeric string which is used for a single login session or transaction on digital devices. It is generally used to enhance security by providing extra authentication. For example, “423193”, “489201’, etc. To generate OTP Swift provides the following methods − Using random() method Using randomElement() method Method 1: Using random() method As we know that OTP is a randomly generated string. So to generate a random string Swift provide an inbuilt function named as random(). It is used to create a random string of ... Read More

Swift program to generate a password

Ankita Saini
Updated on 15-Jun-2023 16:35:50

277 Views

A password is a combination of various characters of a specified length and is used to authenticate or gain access to the system or login to an account. It is designed for security purposes and ensures that only an authorized user can access or log in to the specific account. It is important to select a strong password so that other people cannot crack it. It is generated according to the following conditions − Contains at least one uppercase letter. Contains at least one lowercase letter. Contains at least one number. Length must be 8 characters Contains at ... Read More

Swift program to find the longest word in a string

Ankita Saini
Updated on 15-Jun-2023 17:03:32

357 Views

In Swift, a string is a sequence of characters. So a string can contain small and larger words. Hence using the following methods we can find the largest word in the string. Using component() method Using user-defined method Example Input String: "Rabbit run fast" Output String: "Rabbit" Here, the largest word among all the given words in the string is “Rabbit”. Method 1: Using component() method The components() method is used to create an array of substrings from the given string, where each substring is separated by the specified separator. So here we use the components(separatedBy:.whitespaces) method ... Read More

Swift program to Convert Fahrenheit to Celsius

Ankita Saini
Updated on 16-Jun-2023 11:23:45

429 Views

Fahrenheit is the commonly used temperature-measuring unit. In this scale, the freezing point and boiling point of the water are 32 degrees and 212 degrees. Whereas Celsius is also a temperature-measuring scale. In the Celsius scale, the freezing point and the boiling point of the water are 0 degrees and 100 degrees. So in Swift, we can convert Fahrenheit to Celsius using the following methods − Using Formula Using converted() method Method 1: Using Formula We can easily convert Fahrenheit to Celsius using the mathematical formula. It is the easiest way to convert Fahrenheit to Celsius. ... Read More

Advertisements