In swift, we have three keywords - Open, Public, and Final keyword. All these three words have different properties that help us understand whether the code can be extended to another module or not making the code easy to reuse. We will learn about the keywords' properties in this article.Example Here's an example of how the open keyword is used in a class definition import Foundation open class Person { var firstName: String? var lastName: String? var age: Int? var address: String? } class Student: Person ... Read More
In this article, you will learn how and why to use a de-initializer in the Swift language. You will learn the concept of de-initializing using some examples. When a class instance is no longer required, Swift automatically calls a specific method called a deinitializer. It is utilized to carry out any necessary cleanup prior to deallocating an item from memory. The "deinit" keyword is used to create a deinitializer, which has no parameters or output.Syntax Here is the basic syntax of a de-initializer in Swift class ClassName { // Other properties and methods ... Read More
In swift, the completion handler is a block of code that is used to perform and handle the completion state of a task. For example, completion handlers are very commonly used in network requests using URLSession class. Basically, the completion handler is passed as a function argument and called when the task is completed. It does not impact whether the task is completed successfully or not. You can use the completion handler to perform different actions in your iOS applications. There are some common practices to implement the completion handler such as returning status after cleaning up the unused resources ... Read More
The init() method in Swift is used to initialize the objects of a class. When an object is created using the function Object() { [native code] } of the class, it is automatically called and establishes the object's initial state. To offer customized initialization behavior, such as establishing default values for properties or carrying out other setup chores, the init() method can be changed. Without returning any values, the function is sometimes used to initialize objects with some values. The class's designated initializer, the init() method, should be used to create objects of that class. Here is an example of ... Read More
In iOS development, there are several techniques available to achieve concurrency, You will see different approaches in this article along with some examples. You will learn about Grand Central Dispatch and NSOperationQueue techniques with examples. What is concurrency in iOS? In iOS applications, you can adopt the ability to run the multiple tasks or threads simultaneously by the operating system. In iOS, primarily you achieve concurrency through the use of Grand Central Dispatch (GCD) and NSOperationQueue Developers can prevent blocking the main thread, which updates the user interface, by leveraging concurrency. Instead, they can carry out background activities ... Read More
In this article, you will learn about both the pattern in the Swift language. Also, you will see what are advantages of using these patterns. You will see examples of how you can adopt these patterns in your projects. Using the adapter pattern, you can design a system that allows two different interfaces to work together or communicate between them. You can implement this design pattern with the class or structure by conforming to a certain protocol. Then, you can use an instance of that class or struct to interact with an object that conforms to a different protocol. Using ... Read More
In this article, you are going to learn how to use isKindOfClass in swift with some different examples. It is required many times you need to check the type of a class to perform specific code accordingly. What is “isKindOfClass”? The isKind(of:) method can be used for checking the object type. You can check if an object is an instance of a given type. You can check it for a class or subclass depending on the boolean value returned. In Swift 5, the isKind(of:) method has been replaced by the is an operator and the is a keyword. The is ... Read More
In Swift, you can use the is keyword to test the class type of an object in a switch statement. Also, you will some examples of how to typecast an object to the expected type. Here is an example to test primitive data types In this example, you will check the type for primitive data types such as String, Int, Double, etc. You can use the switch statement to check multiple conditions like the below −Example import Foundation func checkType(_ value: Any) { switch value { case is String: print("The value ... Read More
There are several ways to remove the last character from a string. Let's see some examples of different methods. We will use the below approaches to remove the character from a string − Using the dropLast() method Using the substring(to:) method Using the removeLast() method Using the prefix(upTo:) method Using an array and removeLast() method Using the remove(at:) method Using the dropLast() method In Swift, you can remove the last character from a string by using the String method dropLast(). Here is an example −Example import Foundation let originalString = "Tutorials Point!" let modifiedString = originalString.dropLast() print("Original String: ... Read More
In this article, we will see some examples of how we can read the JSON file using JSONSerialization and JSONDecoder classes. Nowadays, these classes are used in most iOS applications to work with JSON files. You can use the JSONSerialization class to read the JSON file in the Swift language. In order to read a json file, first you will require to convert it into a string or data object. After that, you can pass the string or data object to JSONSerialization class to convert it into a dictionary or array object. JSONSerialization The Foundation framework for iOS and macOS ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP