Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Server Side Programming Articles - Page 339 of 2650
5K+ Views
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
12K+ Views
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
3K+ Views
In Swift, you can read and write a string from a text file using the String(contentsOfFile:) and write(toFile:atomically:encoding:) methods of the String class. You will see some examples of file reading and writing in Swift. String(contentsOfFile:) A class method for creating a string from a file's content is provided by the String class. This method is an initializer where the path to the file must be given. For instance, you can read the contents of local files by passing the path to the main bundle. A new string containing the file's content is returned by this procedure. Keep in mind ... Read More
323 Views
You can use the reactive programming frameworks in iOS application development. To use it, the ReactiveCocoa and RxSwift frameworks are the best options to implement the features. Both frameworks provide a way to handle asynchronous events and data streams and are similar in many ways. What is ReactiveCocoa? You can use the ReactiveCocoa framework to adopt the reactive programming in your iOS, macOS, and watchOS platforms. Using reactive programming, you can handle asynchronous events and data streams easily. This framework has been built on top of Objective-C language. This framework provides you with some tools to work with streams of ... Read More
2K+ Views
What are Storyboards in Swift? In Swift, the Storyboard is a tool that provides you with a user interface to design the UIs of your application. It provides you with a visual representation of all the screens and the connections between them. You can connect all the layout components in your controller classes easily using Storyboard. What is instantiateViewController(withIdentifier:)? You can set the initial view controller programmatically using the instantiateViewController(withIdentifier:) method of the UIStoryboard class. This method takes an identifier string as a parameter, which should match the storyboard ID of the view controller you want to set as the ... Read More
456 Views
In Swift, there are different types of integers − Int − A signed integer with a size equal to the native word size of the computer (32 or 64 bits depending on the platform). Signed integer types with a range of bit sizes include Int8, Int16, Int32, and Int64. UInt − An unsigned integer type with the same native word size as the hardware (32 or 64 bits depending on the platform). Unsigned integer types with designated bit sizes are UInt8, UInt16, UInt32, and UInt64. Here are some examples of using each of the integer types in Swift ... Read More
4K+ Views
We can iterate through a dictionary using various methods in swift. You can iterate a dictionary for keys and values also. We will use the different approaches to iterate a dictionary like below − Using a for-in loop Iterating all the keys in a dictionary Iterating all the values in a dictionary Iterating all the elements using the enumerated() method Using a for-in loop Most of the time we use the for-in loop to iterate through a dictionary. Using a for-in loop, you can iterate all the elements of a dictionary like the below − Syntax for (key, ... Read More
3K+ Views
Swift provides a protocol to achieve the localized description. You can use the LocalizedError protocol to provide a localized description of an error type. This protocol can be conformed by structure, enum, or class. After adopting this protocol, you have to implement the errorDescription property to provide the localized description. Here is an example of a custom error enum that conforms to the LocalizedError protocol − Create a custom error and conform to the Error type In this example, we will create an enum called CustomError to conform to the LocalizedError protocol. In the enum, we will add cases ... Read More
826 Views
In Swift, you can use the .allCases property to enumerate all cases of an enum that have CaseIterable protocol conformance. You will see an example of using the CaseIterable protocol that can help you to iterate all cases of an enum. Using different ways like a for-in loop, reduce, filter, and map functions you can iterate an enum. What is the CaseIterable Protocol? The CaseIterable is a protocol that is used to iterate the enum cases. It synthesized all cases automatically for an enum. Remember that, this protocol can not be applied in the case of associated values. This protocol ... Read More
7K+ Views
In this article, you will see how you can check the OS version to build the functionalities in the Swift language. We will use the following methods to check the OS version in Swift − Using the ProcessInfo class Using the #available attribute Using the UIDevice class Using the @available attribute Using the ProcessInfo class The ProcessInfo class can be used to fetch the versions (Major, minor, and patch) in the Swift language. Below is an example to fetch the iOS version and print it to the console.Example import Foundation let osVersion = ProcessInfo.processInfo.operatingSystemVersion print("OS version major: \(osVersion.majorVersion)") ... Read More