Generics is one of the most powerful tools in Swift. It enables us to write clean, flexible, and reusable code to avoid duplications. Great, isn’t it? Now the question is: How does this tool help me to write cleaner and flexible code? The answer is not that simple, but I promise you will be using generics with confidence after reading this article. Let’s start by saying that generics covers topics like:
XCTestExpectationclass to clean up the source code of your tests
When test driving or writing tests for some tasks we usually have our given, our when, and finally our then. This is easy to picture when we create tests for synchronous tasks. What happens when we have to test driving tasks that don’t behave the same way? If a task is asynchronous, How do we get the results to make our assertions in our test? The answer is fairly simple, Apple provides us with
XCTestExpectation class. …
The term may sound complex to you if you have worked with Swift before, and either you don’t know what patterns are or which available patterns exist in Swift. The good news is that you’ve been working with patterns and you don’t know that(yet 🙂).
Do these tasks sound familiar to you?
Working in our iOS apps can be very challenging in terms of memory handling, this means we need to be very careful with the
object instances allocated in memory and guarantee their correct deallocation.
As you may know instances are deallocated from memory by the ARC or Automatic Reference Counting and there are two types of references on iOS: Strong and Weak.
Strong references are the default type of reference, let’s see a simple object declaration. Imagine that we have a class called
Person and we declare an object as follows:
var person = Person()
In the previous declaration we…