Ankita Saini has Published 319 Articles

Swift Program to demonstrate the string interpolation

Ankita Saini

Ankita Saini

Updated on 13-Jun-2023 17:13:31

126 Views

In Swift, String interpolation is a great feature to create a new string by embedding the value of a variable, constant, function and literal directly in the given string literal. Or we can say that using string interpolation we can create a string by combining static text and dynamic values. ... Read More

Swift Program to Create random strings

Ankita Saini

Ankita Saini

Updated on 13-Jun-2023 16:40:57

221 Views

In Swift, a random string is a sequence of characters. It is generated by randomly selecting characters from a set of available characters, for example: “fbbKDvf”, “dvsWFVsvdv”, etc. So to create random strings Swift provides the following methods − Using randomElement() method Using UUID Method 1: Using ... Read More

Swift Program to remove the last specified character from the string

Ankita Saini

Ankita Saini

Updated on 10-May-2023 13:43:58

241 Views

To remove the last specified character from the string Swift provide a pre-defined remove(at:) function. This function removes a character from the specified position or index. Input String = “Today is cloudy day” Character = “o” Output “Today is cludy day” Where character “o” appears two times ... Read More

Swift Program to convert the string into an array of characters

Ankita Saini

Ankita Saini

Updated on 10-May-2023 13:42:05

1K+ Views

To convert the string into an array of characters Swift proved the following methods − Using Array() initialiser Using append() method Input String = “Cloudy day” Output Array = [“C”, “l”, “o”, “u”, “d”, “y”, “d”, “a”, “y”] Here we converted all the characters present in ... Read More

Swift Program to Update value of Dictionary using key

Ankita Saini

Ankita Saini

Updated on 10-May-2023 11:18:05

687 Views

Swift provides a method named as updateValue() method to update the value of the dictionary using a specified key. If the specified key does not exist, then this method will add that key along with its value in the dictionary. Syntax dict.updateValue(nvalue, forKey: nkey) Here, nvalue represents the new ... Read More

Swift Program to Sort Dictionary by keys

Ankita Saini

Ankita Saini

Updated on 10-May-2023 11:13:21

489 Views

Swift supports a sorted() method to sort all the elements present in the given dictionary. This method sorts the key-value pairs of the dictionary according to their keys. Syntax func sorted(by:) Here, the value of by parameters are − Greater than(>) − To sort the elements into descending ... Read More

Swift Program to sort an array in descending order using insertion sort

Ankita Saini

Ankita Saini

Updated on 10-May-2023 11:10:05

664 Views

In Swift, insertion sort is a sorting technique in which the given array is virtually divided into two parts that are the sorted and the unsorted part. Then the array is searched sequentially, compares two elements from the unsorted part, and moves them into the right place in the sorted ... Read More

Swift Program to sort an array in ascending order using insertion sort

Ankita Saini

Ankita Saini

Updated on 10-May-2023 11:05:43

275 Views

In Swift, insertion sort is a sorting technique in which the given array is virtually divided into two parts that are the sorted and the unsorted part. Then the array is searched sequentially, compares two elements from the unsorted part, and moves them into the right place in the sorted ... Read More

Swift Program to convert the string into an array of characters based on the specified character

Ankita Saini

Ankita Saini

Updated on 10-May-2023 09:33:31

83 Views

In Swift, convert the string into an array of characters based on the specified character using the split() function. The split() function splits the given string at the specified separator and returns the result in an array. Input String = “Today is cloudy day” Character = “y” Output [“toda”, ... Read More

Swift Program to Sort a Dictionary By Values

Ankita Saini

Ankita Saini

Updated on 09-May-2023 17:18:18

349 Views

Swift supports a sorted() method to sort all the elements present in the given dictionary. This method sorts the key-value pairs of the dictionary according to the values. Syntax func sorted(by:) Here, the value of by parameters are − Greater than(>) − To sort the elements into descending ... Read More

Previous 1 ... 3 4 5 6 7 ... 32 Next
Advertisements