What are Threads in Swift?

What is the Thread? A Thread is a small set of instructions that can be executed independently from the main program. Threads are often used to improve program performance by allowing multiple tasks to be executed at the same time. The Thread has its own stack, registers, and program counters. Threads share memory address space, and it is possible to communicate between Threads using shared memory space. How to use it?...

January 20, 2024 · 2 min · Dmytro Chumakov

DispatchGroup in Swift

What is DispatchGroup? DispatchGroup provides a mechanism to track the completion group of tasks. How DispatchGroup works? DispatchGroup has three main methods, enter, leave and notify, that allow you to control the completion of a specific task. let dispatchGroup = DispatchGroup() dispatchGroup.enter() dispatchGroup.leave() dispatchGroup.notify(queue: .main) {} Let`s talk about each of these methods. enter — manually indicate a block has entered group. leave — manually indicate a block in the group has been completed....

January 10, 2024 · 2 min · Dmytro Chumakov

Concurrency in Swift

What is concurrency? The system can perform multiple tasks simultaneously. By tasks, I mean code or instructions. Modern computer chips have multiple cores that allow developers to create and run various tasks on multiple cores. Even if your chip has one core operating system it will provide context switching mechanism by enabling it to execute multiple tasks concurrently. Material about processes, threads I will skip explaining concepts about processes and threads because it is a vast topic, and it will take a lot of time to explain it....

January 7, 2024 · 6 min · Dmytro Chumakov

What are value types in Swift?

What are value types? Value types play a central role in programming languages by grouping data values. `Value type” is a type of data copied when assigned to a new variable. struct Storage { var data: String = "some data" } let originalStorage = Storage() var copiedStorage = originalStorage // `originalStorage` is copied to `copiedStorage` How can you pass value types? You can pass value type by copying value. struct Storage { var data: String = "some data" } let originalStorage = Storage() var copiedStorage = originalStorage // `originalStorage` is copied to `copiedStorage` copiedStorage....

December 28, 2023 · 2 min · Dmytro Chumakov

How to prevent memory leaks?

I was searching for tools that could help me find memory leaks faster and would be simple in implementation without affecting performance and memory size of application. I found a fantastic fit for this task LifetimeTracker developed by Krzysztof Zabłocki. All you need is to add LifetimeTracker package to the project, inherit from LifetimeTrackable protocol, and add two lines of code. class Department: LifetimeTrackable {} trackLifetime method to init of instance that you are going to verify, and lifetimeConfiguration property where you set max number of valid instances....

December 24, 2023 · 1 min · Dmytro Chumakov