Swift

There are a few different ways of how to create an Array with default values in Swift. Below are a few Swift code examples of creating an Array. Each example creates an array with some initial values. Create an Array of Strings var appleProgrammingLanguages: [String] = [“Swift”, “Objective-C”] Thanks to Swift’s type inference, you don’t…

Read More Create an Array with Default Values in Swift

In this tutorial, you will learn how to determine the current device model in Swift. To determine the current device model in Swift, you can use the utsname struct provided by the Darwin framework, which contains information about the system. This method involves getting the machine hardware description and then mapping it to the corresponding device…

Read More Determine Current Device Model in Swift

To present a ViewController in a NavigationController you can wrap ViewController into a NavigationController as it is in the example below. Then present NavigationController which contains ViewController. // Register Nib let newViewController = CustomSignupViewController(nibName: “CustomSignupViewController”, bundle: nil) let navigationController = UINavigationController(rootViewController: newViewController) // Present View “Modally” self.present(navigationController, animated: true, completion: nil)  

Read More Present ViewController in NavigationController

Swift provides powerful tools for comparing and equating custom objects using the Comparable and Equatable protocols. In this tutorial, we will explore how to use the Comparable protocol to compare custom objects based on their properties, and the Equatable protocol to determine whether two objects are equal. By the end of this tutorial, you will…

Read More Comparable Protocol: How to Compare Custom Objects

There are different ways to test that the UIViewController has been successfully pushed onto the navigation stack and in this tutorial, I will cover a few of them. For this tutorial, I have created a simple project with two view controllers on the Main.storyboard. The very first view controller has a button. When the button…

Read More Test View Controller Push to Navigation Controller

There are a few different ways to Unit test code that throws an Error in Swift and my preferred way is to use the XCTAssertThrowError and XCTAssertNoThrows. I will also share with you how to use the traditional way of handling an error with the do-try-catch. Error To Be Thrown Let’s assume that we have…

Read More Unit Testing Code That Throws Error in Swift

There are different ways to load UIViewController in a Unit Test and in this tutorial you will learn three of them. Loading UIViewController from Main.storyboard, Loading UIViewController from XIB, Loading UIViewController that is not on the Main.storyboard and does have an interface XIB file. This is a type of UIViewController that creates views programmatically. Loading…

Read More Ways to Load UIViewController in a Unit Test