- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 517 Articles for Swift
128 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. Syntax var myString = “hello! \(x). How are you?” We can perform string interpolation by wrapping a string literal or constant or variable in a pair of parentheses that is prefixed by a backslash(\) for example, \(x). Example 1 In the following Swift program, we will demonstrate how ... Read More
107 Views
In Swift, a string is a sequence of characters that represent in between double quotes, for example: ”Learn Swift”, “tutorialspoint”, etc. But when you print the string double quotes were removed by the compiler and you will get Learn Swift, tutorialspoint in the output. So if you want to print double quotes in the output, then you have to place the backslash character or escape character(\) before the double quotes you want to print inside the given string. It tells the compiler that the character should be treated as a literal character, it is not part of string syntax. ... Read More
153 Views
In Swift, escape sequence characters are those characters who do not represent themselves when they are used inside a string. Instead, they tell the compiler to perform the specified task. They are non-printable characters. Swift supports the following escape sequence characters in the string − Escape Sequence Characters Description It is a newline character. It tells the compiler to move to the new line. \t It is known as the horizontal tab. It tells the compiler to leave the tab. \r It is known as carriage return. It tells ... Read More
242 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 randomElement() method Swift provides an inbuilt function named as randomElement() method. This function returns a random element from the given sequence or collection. Syntax func randomElement() It returns random elements. If the given collection is empty, then it will return nil. Algorithm Step 1 − Create a ... Read More
714 Views
In Swift, a substring is a small sequence of characters present in the large string, for example, “Car color is blue”, then “Car”, “color”, “is”, and “blue” are the substrings of the given string. Swift provides the following methods to check if the string contains the specified substring or not − Using range(of:) method Using contains() method Using Regex Method 1: Using range(of:) method The range(of:) method is used to find the range of the first occurrence of the given substring in the string. So using this method we can check if the given substring is present in ... Read More
705 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 value and nkey represents the key to which we want to update or add value. If the given key exists in the dictionary, then its value is replaced by the new value. If the given key does not exist, then it will add the nkey and nvalue in the dictionary. ... Read More
530 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 order. Less than(
686 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 part. Using insertion sort, we can easily sort the array elements in ascending or descending order. So in this article, we will learn how to sort an array in descending order using insertion sort. Working of insertion sort Given unsorted array To sort the array in descending order, compare ... Read More
282 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 part. Using insertion sort, we can easily sort the array elements in ascending or descending order. So in this article, we will learn how to sort an array in ascending order using insertion sort. Working of insertion sort Given unsorted array − To sort the array in ascending order, ... Read More
251 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 in the input string so using the remove(at:) function we removed the last appearance of the “o” character from the string. Hence the output string is “Today is cludy day”. Syntax Str.remove(at:Idx) Where Str is the input string and idx is the valid position/index of the specified character to ... Read More
To Continue Learning Please Login
Login with Google