In UIKit it is very straight-forward to set a background on any view — in SwiftUI it is a little bit trickier

Multi-colored background behind bike.
Multi-colored background behind bike.
Photo by Autumn Studio on Unsplash

From plain colors to gradients and custom views, this article will teach you how to add a background to a SwiftUI view, and how to wrap the functionality to reuse it whenever you need it.

The Basics

Let’s start with a simple view:

Colored background

In this article I will explain to you two ways to add a colored background to our view:

1. Using ZStack

The first approach consists of creating a ZStack structure where the color background will be the second layer behind the actual content:

2. Using the .overlay view modifier

The second approach consists of adding the selected color as the main element, and then a .overlay


Combine to the rescue

Data
Data
Photo by Markus Spiske on Unsplash.

We still need passwords. Strong passwords.

And strong passwords mean complex validations.

Bank info, family photos, emails, etc. Unauthorized access is a major problem when sensitive data is behind the wall. For that reason, you need to create strong, complex passwords more than ever, and they also need to be validated.

In this article, you will learn how to create a great validation system using SwiftUI and Combine, and the main principles behind its construction.

What Is a Validation System?

A validation system allows an app to evaluate a user input stream and decide if that data is valid based on some rules.

Face ID…


SwiftUI

Custom placeholders for making the wait more pleasant

Waiting is boring.

None of us like it.

But sometimes we have to.

In 1993, an article named Response Times: The 3 Important Limits by User Experience world-reference Nielsen Group stated the following:

1 second is about the limit for the user’s flow of thought to stay uninterrupted, even though the user will notice the delay.

10 seconds is about the limit for keeping the user’s attention focused on the dialogue. For longer delays, users will want to perform other tasks while waiting for the computer to finish.

This remains valid in 2020: Response time when waiting for an event…


SwiftUI

A state-based approach in SwiftUI

Author: Pablo Blanco

Swift

How to create a great structure for environment configuration in Swift

Photo by Jarvik Joshi on Unsplash

In real-world apps, developers deal with many different backend environments. Every environment has its properties and configuration so it is important to have a proper structure to manage them.

In this article, I explain how to create a great structure for environment configuration in Swift, that can easily evolve but rely stable on.

1. Endpoint structure

We start by creating an Endpoint struct declared like this:

2. App endpoints

Our app has two different features:

  • getUsers: Get the users from a city
  • addUser: Add a new user

So, let’s declare an enumeration with two different cases:

3. Environment configuration

To have a clear understanding of the environments…


Photo by Pavel Anoshin on Unsplash

Spending time developing new features is great.

Spending unnecessary time updating your REST API endpoints is not.

But… how to avoid it?

A non-unified approach to managing endpoints can provoke many issues if API updates imply a lot of similar, repetitive code changes.

In this article, you will understand how to structure your REST API endpoint configuration in a better way, by using some swifty techniques.

Let’s review this piece of code. It creates and launches a request to get some user data from a REST API:

A sample request for getting users

Ok, the code works. But this implementation…


Photo by Lily Li on Unsplash

Styling makes your product recognizable.

Styling makes your brand stronger.

Styling is key.

But when apps grow in size, styling gets harder and harder. That’s why centralize styling becomes a must.

In this article, you will understand why styling schemes are necessary and how to create and apply a styling scheme using SwiftUI.

Check out this code about three different buttons:

This code works and looks good, but also has some problems.

  • Repetitive code on every button will bring in the end to issues and failures.
  • Hardcoded values: Colors, paddings, etc. are set directly on the view. If in…


Photo by Kristopher Roller on Unsplash

During the process of being hired as a developer, you will be probably asked to pass an online coding test. No matter your experience, this kind of tests can be hard and stressful. In this article, you will get some tips to make your coding test better:

  1. Prepare the test
  2. Code your solution
  3. Submit the code

1. Prepare the test

Master the coding platform

Take some moments to know the coding platform. Please, don’t skip tutorials. Some important things you should know before starting code are:

  • How the challenge gets started
  • How to submit your solution
  • How to check the remaining time
  • How to select the programming language…


UI Testing is a great thing to keep apps maintainable and reliable during its whole lifecycle, but sometimes this user interface testing could become a big pain.

Here we will transform a bad test case into a better one, applying some code refactors.

In this article, it’s assumed that the reader knows some basic usage of UI testing.

The bad test case

This test was recorded with the Recording feature from XCode. The actions made by the user are in-code commented:

func test1() {    // 1. The user taps in a textfield
app.textfields["Send something..."].tap()
// 2. The user types the text “Hello
app.textfields["Send something..."].type("Hello")

Pablo Blanco

Senior iOS Developer @Teamwire

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