Image for post
Image for post

UITESTS

How to interact with Apple dialogs and other interrupts in your UITests

This week, I figured out I was missing a relevant part in my exploration of the automated UI Tests: the interaction with Apple dialogs. They can appear in various moments, to ask for user permissions for example. How can we interact with them?

A first guess would be that they behave like the rest of the app: we could query them with theXCUIElement APIs. However, that is not (directly) the case: such dialogs can be prompted in non-deterministic moments. It is the system that decides when to present them.

Therefore, let’s see together how we can work with them,

The App


Image for post
Image for post

UI TESTING

How to bake an automatic recording of UITest to see what has happened.

I already talked about UI Testing in several other articles and I find this topic fascinating. While discussing with my colleagues at Bending Spoons how we could use them, it emerged that it could be cool to have a recording of the UITest execution. This could save a ton of time for our QA colleagues, for example.

I take a look at the matter and I’d like to share with you how we can automatically record any UITest, in a completely automatic way.

The App


Image for post
Image for post

PROGRAMMING

How to manage the keyboard automatically and forget about it.

Every time we write an iOS app there is at least one screen where the user has to input something: their username and password to log in, their name in a game, a note, …

The keyboard handling is a basic use case but Apple forces us to manage it manually. This somehow annoys me so let’s see how we can automate this, once and for all.

How Does It Work?

When we add a control on the screen — such as a UITextField — , we launch the app and we tap on the control, the keyboard appears and we are able to input some text. …


Image for post
Image for post

PROGRAMMING

How to properly use enums to model your data

Swift is an interesting language. It is very friendly for new developers: its syntax is concise and simple to grasp, as well as its main concepts.

However, it takes a lot of time to really master it. Every feature of the language has some details that are deeper than what described in swift.org’s Language Guide.

In today’s article, I’d like to explore some more advanced usages of enums. Enums are extremely powerful and they are often underused or misused. I hope to shed some light on ways to use them that you may have not thought about.

Models Exclusivity


Image for post
Image for post

UI DEVELOPMENT

How to implement an App using both UIKit and Swift UI

In 2019 Apple presented SwiftUI, a new UI framework to develop our apps in a declarative way. Before that, all the iOS apps have to use UIKit to implement their UI.

SwiftUI promises incredibly advantages while developing:

  • It is fully declarative, reducing the number of bugs in the code.
  • It arranges the views automatically on the screen, saving us the time used to write layout code.
  • It offers a preview panel in Xcode to show the UI while you write it, making prototyping faster.

Therefore, the overall goal to achieve is to reduce the development time required to build an App. …


DEVELOPMENT

How to write your first “interactive” widget

With iOS14, Apple introduced a new framework to implement widgets: WidgetKit. Widgets are small pieces of UI, rendered in the Springboard, that offer quick access to some information from our apps. They come in 3 sizes: small, medium, and large. A small widget occupies the space of 4 app icons. A medium one, the space of 8 app icons. A large one, the space of 16 app icons.

Image for post
Image for post
On the left a large and a medium widget. On the right a small widget.

Widgets can only be implemented in SwiftUI and, by quoting the documentation:

Widgets present read-only information and don’t support interactive elements such as scrolling elements or switches. …


Image for post
Image for post

TESTING

How to use snapshot testing to check if your UI has changed.

It could happen that the output of a feature of your app is not easy to unit test because it is something visual, like an image or a video. Or maybe, the main goal of your app is to implement some fancy filter to apply to a picture.

Even in these cases, we would want something that can protect us against changes in the codebase and reassure us that the implemented logic is sound and solid. What can we do in these contexts where unit tests looks not that useful?

The people from pointfree.co have developed and open-sourced a very interesting library called Snapshot Testing. Thanks to this library, we can take a snapshot of a view controller, a view, or any object, and compare them to see if anything has changed in the codebase. This kind of testing is called regression testing and it is extremely useful when we build our app incrementally: it can prevent some unwanted changes in the UI. …


Image for post
Image for post

UI Programming

How to customize the text in your app.

The main way to show some text to the users is through UILabels. Labels let us customize their text with some attributes. Most of us always use the same attributes to customize them.

However, the NSAttributedString API’s offer so many customization possibilities that I took some time to explore them. In today’s article, I’d like to share them with everybody, showing how they behave so that, the next time, we could use the right attribute for the job.

The Base API


Image for post
Image for post

UI Programming

How to properly add some curved text in your app

Another week, another feature for our app. This week I had to make some research about how to add some curved text to our app.

I searched a lot and end up on different resources: from an official (but outdated) Apple example with CoreText, to a post on Stack Overflow written in Swift 2, 3, and 4. However, none of them offered a straightforward, easy to follow, mathematically sound approach.

I made several experiments, trials, and errors, before reaching this solution. I had to properly understand several concepts of how the text can be rendered on the screen and it could be useful to write them on (digital) paper for both the future me and anyone who could need it. …


Image for post
Image for post

Programming

How to properly propagate gesture updates in an MVVM architecture

I have never worked with gestures in iOS. Seems weird, but it’s the truth. This week, I had to integrate a gesture in an app to test a couple of things that we are developing, but I struggled a bit to make it work properly with our MVVM architecture.

At Bending Spoons we are extremely eager to help out our colleagues and to share what we know. Lucky for me, I have a colleague who worked on that same issue before and shared a nice trick to solve the problem elegantly. …

About

Riccardo Cipolleschi

Hi everybody, I’m Riccardo. Senior iOS Engineer at Bending Spoons, I breathe iOS development: apps and tools. I love to share my knowledge with others.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store