How to develop accessible iOS apps

When a user navigates your app with an assistive technology, the interface is not the same as the one visible on the screen. They navigate a modified version that iOS creates, called the accessibility tree or Accessibility UI (AUI).

The difference between SwiftUI and UIKit is how iOS creates the AUI. In UIKit, iOS builds the visual interface and then generates an AUI from the screen. The accessibility API then combines this with any accessibility modifications you have made in code.

With complex UI or custom components, it can be hard for the API to interpret the experience you intended…


How to develop accessible iOS apps

Photo by Farzad Mohsenvand on Unsplash

An important aspect of making your app accessible is to localize your app. Localization is the process of adapting a product or content to a specific locale or market. This includes translating, but also adapting graphics, content, and layout to suit the tastes and consumption habits of the target markets. You have to convert currencies, units of measure, formats of dates, addresses, and phone numbers to the local requirements as well.

Even if you release an app only in a specific country, keep in mind there are also people in that country that doesn’t have that country’s language as their…


Photo by Thiébaud Faix on Unsplash

As many of you might know UITextField has a delegate protocol to notify you if the text of the textfield changes. But the only method that does that is textField(_:shouldChangeCharactersIn:replacementString:). This method is meant to stop editing and it provides the text before change, the range of the changed characters and what they are replaced with.

Some developers use this method to compute the final text from the parameters of this method. They can’t use the UITextField’s text, provided as a parameter, because the method is called before the actual changes will happen.

But there is an easier way! UITextField


Photo by Graphic Node on Unsplash

Almost in every project I need a view or a button that has rounded corners and sometimes even a bit of shadow at the same time. It can be a bit hard when you start to apply both to the same view.

This is a base class you can use to create a round button with or without shadow. You can make something similar for views:

@IBDesignable class RoundButton: UIButton {   // MARK: - Properties   @IBInspectable var cornerRadius: CGFloat = 0.0 {
didSet {
setNeedsLayout()
}
}
@IBInspectable var shadowColor: UIColor = UIColor.darkGray {
didSet {
setNeedsLayout()
}
}

Photo by Markus Spiske on Unsplash

A bit is the smallest piece of information that can be 1 or 0 (on/off). Eight bits together are called a byte. A UInt8 in Swift is represented by 8 bits. The difference of this unsigned integer with the signed integer Int8 is that Int8 uses 1 bit to signify whether the integer is positive or negative. Having eight bits to represent a number means we can represent 2⁸ = 256 different numbers with UInt8.

0 = 00000000 2 = 00000010 4 = 00000100 8 = 00001000 1 = 00000001 3 = 00000011 5 = 00000101 9 = 00001001 6…

Photo by Jason Rosewell on Unsplash

VoiceOver is often referred to as Apple’s screen-reading technology that gives users control over their device without seeing the screen. It is one of the tools used to make an app more accessible. Most people think it only benefits the visual impaired users and that it is a lot of work to implement… But actually both are not true! Experiencing your app through VoiceOver reveals things like copy, order or navigation that doesn’t sound right and this can be an indication that visually it may not read or navigate well either. …


Photo by Jantine Doornbos on Unsplash

The Basics

To decode a JSON structure and encode the model in your app back to JSON, you can conform your model to the Swift Codable protocol. This is a combination of two other protocols: Decodable and Encodable.

This is great for simple JSON arrays and dictionaries like:

let json = """
[
{
"name": "Annual Travel Insurance",
"paymentFrequency": "yearly",
"description": "Travel safe all year round."
},
{
"name": "Car Insurance",
"paymentFrequency": "monthly"
}
]
""".data(using: .utf8)!

You can conform your model to the Codable (or Decodable) protocol:

struct BankProduct: Codable {
var name: String
var paymentFrequency: PaymentFrequency
var description: String? …

Photo by Dmitry Ratushny on Unsplash

When making a network call we need a callback, or so called completion handler, that tells us if our call was successful and returns some data or if something has failed.

The traditional Objective-C approach of completion handlers has it’s shortcomings: it is not clear what you can get back. Data, an error, both or neither of them.

func load(completion: @escaping (Data?, Error?) -> Void) {
....
}

The dataTask() method from URLSession is even worse: it calls its completion handler with (Data?, URLResponse?, Error?). So it has eight possible outcomes.

In Swift we can do better. We have generics…


Photo by Helloquence on Unsplash

In part 1 I explain how you can improve the architecture of your app to make it better unit testable.

Writing tests should be as much fun as writing code, right? But why isn’t it? That’s what I asked myself and I noticed that every time I tried to write some tests, I didn’t know where to begin or what to test. And if I had an idea, it turned out I couldn’t test it or I didn’t know how to test it.

After a while I started to realise that if you have a clear structure of your code…


Photo by Frances Gunn on Unsplash

Do you know these moments that you start an app convincing yourself you need to certify quality by writing as much unit tests as you can? Until that moment you find out it’s almost impossible or takes so much time to write the proper unit tests. Well I had these moments and started realising that a good pattern in your app helps writing unit tests.

A good pattern comes first

In order to write better unit tests you need a consistent pattern. The MVC-pattern is definitely not the best pattern if you want to write better unit tests. …

Jeroen de Vrind

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