- Trending Categories
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
![Ankita Saini](https://www.tutorialspoint.com/assets/profiles/489852/profile/60_2374666-1658225115.jpg)
341 Views
In swift, Bubble sort algorithm is the easiest search algorithm. This algorithm sorts the elements by repeatedly swapping adjacent elements if they are not present at the right place. This algorithm works well only for small set of elements, it is not suitable for larger number of elements because its average and worst case time complexity is high. So the working of the bubble sort is − Suppose we have the following array − Now we sort the array in ascending order using the bubble sort. Here starting from the first index we compare the first and second element. ... Read More
![Ankita Saini](https://www.tutorialspoint.com/assets/profiles/489852/profile/60_2374666-1658225115.jpg)
1K+ Views
In swift, Binary search algorithm is used to search element from the sorted array. It repeatedly divides the search interval into half and then search the specified element. In the binary search algorithm, the input array must be in sorted order to reduce the time complexity. Algorithm Step 1 − Create a function to implement a binary search algorithm. Step 2 − Inside the function, first we find the lower bound and upper bound range of the given array. Step 3 − Run a while loop till LBound
![Nitin Aggarwal](https://www.tutorialspoint.com/assets/profiles/558477/profile/60_3034393-1669108333.jpg)
498 Views
In Swift, you can create an additional initializer to provide default values for the properties. You can use the convenience keyword to add this functionality. Let's look at some examples of how to use a convenience initializer in the Swift language. What is a convenience initializer in Swift? In Swift, a secondary initializer in a class that provides extra or alternative ways to create an instance of that class is marked with the convenience keyword. The initialization procedure is streamlined and made simpler, which makes it easier for the developer to deal with the class. The designated initializer of the ... Read More
![Nitin Aggarwal](https://www.tutorialspoint.com/assets/profiles/558477/profile/60_3034393-1669108333.jpg)
433 Views
In real iOS applications, you often need to support localization to ensure the app's accessibility around the world. By incorporating localization into your app, you can gain more users. In Swift, we use the NSLocalizedString function to create a localized string. What is localization? Localization is the process of allowing various language support in your apps. Instead of utilizing the software in a single language, it helps to create a more localized experience for users. Localization will be quite simple to integrate in your application. Apple offers a totally native method for integrating localization in your program.Syntax The syntax for ... Read More
![Nitin Aggarwal](https://www.tutorialspoint.com/assets/profiles/558477/profile/60_3034393-1669108333.jpg)
780 Views
In Swift, the equivalent of the Objective-C method respondsToSelector is the responds property of the NSObject class. To check if an object responds to a particular selector, you can use the responds(to:) method which is declared in the NSObjectProtocol. Here's the syntax − if objectName.responds(to: #selector(methodName)) { // do something if the object responds to methodName } else { // do something else if the object doesn't respond to methodName } In this syntax, objectName is the object that you want to check, and methodName is the selector that you want to check ... Read More
![Nitin Aggarwal](https://www.tutorialspoint.com/assets/profiles/558477/profile/60_3034393-1669108333.jpg)
372 Views
In Swift, we can use methods like dropFirst, Index(after:), and many others that can remove the first character of a string. In this article, we are going to learn various examples of these functions and understand how can we remove the first character of a string. Using the dropFirst method In this method, we are going to use the dropFirst method to remove the first character from the string and make the new string start with the second character. In case the original string is empty or has a single character in it, the result will be an empty string.Example ... Read More
![Nitin Aggarwal](https://www.tutorialspoint.com/assets/profiles/558477/profile/60_3034393-1669108333.jpg)
3K+ Views
In Swift, you can pass an array by reference in a function as an argument using inout keyword. In Swift, arrays are value types by default. In other words, they pass a value rather than a reference. If you pass an array to a function as an argument, it makes a copy and passes that copy to the function. First, let's understand what happens when we pass an array in a function as a value. func passByValue(_ array: [Int]) { array.append(100) } let numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] passByValue(numbers) ... Read More
![Nitin Aggarwal](https://www.tutorialspoint.com/assets/profiles/558477/profile/60_3034393-1669108333.jpg)
179 Views
In Swift, working with JSON objects is very easy with the JSONDecoder class. It is always necessary to create model classes or structs with the Codable protocol. One single mistake leads you to fail to decode the complete JSON object. Let's explore some examples to understand when this failure might occur and how you can handle it in Swift. What is the JSONDecoder class? The JSONDecoder class is then used to parse the JSON data from the file into an instance of the given Type either a class or structure. The decode(_:from:) method is used to deserialize the JSON data, ... Read More
![Nitin Aggarwal](https://www.tutorialspoint.com/assets/profiles/558477/profile/60_3034393-1669108333.jpg)
1K+ Views
We can define a subclass that is inherited from a superclass in the Swift language, That means you can override its properties and methods using the override keyword. However, you cannot override the properties with a different type in the subclass. By default, the subclass must override the properties of the same type as the superclass type. For example, let's say you have a Person class with name and age properties of type String and Double − class Person { let name: String let age: Double ... Read More
![Nitin Aggarwal](https://www.tutorialspoint.com/assets/profiles/558477/profile/60_3034393-1669108333.jpg)
2K+ Views
URL encoding is an essential part of iOS app development. Many times, you will need to encode the URL to communicate with servers. Let's look at some examples of how you can encode an URL in Swift and Objective-C. URL Encoding in Swift In Swift, you can use the addingPercentEncoding(withAllowedCharacters:) method for URL encoding. URL Encoding in Objective-C In Objective-C, you can use the stringByAddingPercentEncodingWithAllowedCharacters method for URL encoding. Encode a URL in Objective-C In Objective-C, you can encode a URL string using the stringByAddingPercentEncodingWithAllowedCharacters: method of the NSString class. Here's an example NSString *stringToEncode = @"https://www.exampleserver.com/complete path with spaces"; ... Read More