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. I attached links to the material to help you understand it more deeply. https://youtu.be/4rLW7zg21gI?si=49hq8Wrbpmeev41k https://youtu.be/r2__Rw8vu1M?si=b7b257Qu4Bty7OxA I will focus on implementation. ...

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.data = "new data" // Changes `copiedStorage`, not `originalStorage` print("\(originalStorage.data), \(copiedStorage.data)") // prints "some data, new data" The effect of assignment, initialization, and argument passing creates an independent instance with a unique copy of its data. ...

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

How to find memory leaks?

The common way to find memory leaks is by using Xcode Instruments. All you need is the following: Open Xcode Instruments Choose Leaks option Select Simulator where you are going to test your application Select your installed application When you finish preparation, you can start immediate recoding and check application for leaks. To do that, you need to open Simulator and try some cases that could cause memory leaks. ...

December 20, 2023 · 1 min · Dmytro Chumakov

ARC in Swift

What is ARC? Swift uses Automatic Reference Counting (ARC) to track and manage your app’s memory usage. In most cases, this means that memory management “just works” in Swift, and you don’t need to think about memory management yourself. ARC automatically frees up the memory used by class instances when those instances are no longer needed. - Apple ARC In Action In this example, we assign an instance to the reference1 property. ...

December 17, 2023 · 5 min · Dmytro Chumakov