Ankita Saini has Published 277 Articles

Swift Program to remove the last specified character from the string

Ankita Saini

Ankita Saini

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

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

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

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

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

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

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

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

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

Swift Program to Search an Element in a Dictionary

Ankita Saini

Ankita Saini

Updated on 09-May-2023 11:51:09

In a Swift dictionary, we can search for an element that is either a key or value with the help of contains() function. The contains() function will return a boolean value which represents whether the specified element(key or value) is found or not. Syntax dict.contains{$0.key == “KeyName”} Here, dict ... Read More

Swift Program to Replace Elements in a Dictionary

Ankita Saini

Ankita Saini

Updated on 09-May-2023 11:49:30

In Swift, a dictionary is an unordered collection of key-value pairs. So, to replace the value of a key Swift provides bracket notation or subscript notations. Using this notation we can also add new key-value pair in the dictionary if the specified pair does not exist. Syntax dict[keyName] = “Value” ... Read More

1 2 3 4 5 ... 28 Next
Advertisements