Swift

There are times when we need our UI Test code to pass some information to our mobile app, not by typing it into a Text Field or a Text View but by sending it as a command-line argument or as a launch environment property. To pass a command-line launch argument or an environment key-value pair…

Read More UI Testing. Launch Arguments & Launch Environment

By default, Xcode will automatically create a screenshot of the app if UI Test fails. If needed, we can also create a screenshot programmatically and include it in a Test Report with the help of the XCTAttachment class. In this tutorial, you will learn how to create a screenshot of a specific UI element as well…

Read More XCUIScreenshot – Creating Screenshots in UI Test

When writing unit tests, developers try to follow the F.I.R.S.T principle as much as possible. F.I.R.S.T is a combination of multiple principles. Let’s learn what these are. Fast The first letter in the F.I.R.S.T principle stands for – Fast. Unit tests are small pieces of code that perform one, specific task. Because unit tests are…

Read More The F.I.R.S.T. Principle in Unit Testing

The addTeardownBlock(_:) runs right after the test method ends and before the instance’s tearDownWithError() method is called. Below is an example of a TestCase class that does not test anything and only demonstrates the order in which the setUp() and tearDown() methods are called. When will the addTeardownBlock(_:) run? The addTeardownBlock will run after the test method is…

Read More addTeardownBlock Example in XCTestCase

In this tutorial, you will learn how to create UISlider in Swift programmatically. UISlider is a UI control that is used to select a single value from a continuous range of values. Below is an image of UISlider control. Create UISlider Programmatically To create UISlider control programmatically, you need to create a new instance of…

Read More Create UISlider in Swift Programmatically

In this tutorial, you will learn how to create both a one-dimensional and multidimensional arrays in Swift. After reading this tutorial, you might also be interested in learning how to use FlatMap and Map when working with arrays. How to Use flatMap in Swift. Code Examples, How to Use map(_:) in Swift. Code Examples, Ways…

Read More Multidimensional Array Example in Swift

In this tutorial, you will learn how to create a UICollectionView programmatically in Swift. You will learn how to create a new UICollectionView with UICollectionViewFlowLayout and will learn how to make it display a few cells. You will also learn how to make your UIViewController conform to a UICollectionViewDelagate to handle events when user taps on…

Read More Create UICollectionView Programmatically in Swift

In this tutorial, you will learn how to add days, months or years to the current date in Swift. To work with dates I will use Date(), DateComponents() and Calendar objects. I will first get the today’s current date and then will use the DateComponents() to add to a current date another day, month or…

Read More Add Days, Months, Years to Current Date in Swift

In this Swift tutorial, you will learn how to encode UIImage data to Base64 string. To verify that the UIImage data was correctly encoded into the Base64 string, we will decode the Base64 string back into image data and will create a new UIImage using this data. Create UIImage Before I can encode existing image…

Read More UIImage Base64 Encoding and Decoding in Swift