I’ve been playing around with Combine for a while now and had some trouble navigating all the new protocols and types, especially when it came to extensions. In this article, I’ll show you how to properly extend existing publishers and how to wrap them when creating your own custom publishers.
One of my favorite uses of Combine is how easily composable everything is. There’s no need to create custom classes unless you really need to keep track of an external object:
Since all articles require a nonsense example, our example is going to be a publisher that streams the…
When it comes to benchmarking the speed of code, it’s common for people to boot a playground, throw in a
Date object, and calculate the time difference after a piece of code runs. That may give you a rough estimate, but it can also be very misleading. The difference between code running in debug builds versus release ones can be massive, and the size of the input (assuming we're benchmarking an algorithm) can also make a huge difference in the speed of a function.
In this article, we'll see how to properly benchmark your Swift code. Note that we're not…
Actors are a feature that is part of Swift’s Structured Concurrency, which brings a brand new format to write and deal with asynchronous code. Although what Swift brings is new to the language, it’s not new to tech itself. Many languages supported actors and
async/await before Swift, but one interesting thing is that they are all implemented similarly. By having these features now in Swift, there’s much we can learn from what developers experienced by using them in other languages.
Just like other “How X Works Internally in Swift” articles, the purpose of this one is to explore how actors…
RealityKit Object Capture is a feature introduced in Xcode 13 that allows you to create 3D objects from photographs using a process called photogrammetry. Although intended for retailers to enhance their online shopping experience by creating models out of things like furniture and using them in augmented reality experiences, RealityKit is incredibly easy to use for anything you may want, like 3D printing random things from your house.
To use Object Capture, you must:
Capturing photographs of the object…
I’ve been meaning to write an article about computer science fundamentals and how it can improve a programmer’s career for a long time, but I always had trouble finding a good way of introducing this topic. The reason I’d like to talk about this is first that, well, I really like this field and I feel that most of my programming ability today is a result of having studied this, but also because this topic has been a constant source of frustration for me, and I’ve been hoping I could address that.
The reason? There’s a part of the tech…
Concurrency is the entry point for the most complicated and bizarre bugs a programmer will ever experience. Because we, at the application level, have no real control over the threads and the hardware, there’s no real way of creating unit tests that guarantee your systems behave correctly when used by multiple threads at the same time.
In this article, I’ll share my favorite methods of ensuring thread safety as well as analyzing the performance of the different mechanisms.
I personally define thread safety as a class’s ability to ensure “correctness” when multiple threads attempt to use it at the same…
The easiest way to create a paid macOS app is to simply put a price tag in the App Store, but it’s a common practice nowadays to provide a free download that can later be upgraded to a pro version. In this article, we’ll use our knowledge of serial numbers and asymmetric cryptography to create license files that cannot be reverse-engineered and use them to activate an app’s premium features.
The safest way to include a pro version in your app is to have a backend that is capable of providing content to premium users, but not every app falls…
Bridging to/from Objective-C is an important part of Swift development due to the Obj-C history of Apple’s platforms. Unfortunately, there are some hidden caveats that could lead to bizarre situations that would be impossible in a pure Swift environment. When dealing with Objective-C types, it’s useful to check if they don’t have a history of being too different from their Swift counterparts.
The reason for this caution is that bridging can be completely hidden from you. …
@inlinable attribute is one of Swift's lesser-known attributes. Like others of its kind, its purpose is to enable a specific set of micro-optimizations that you can use to increase the performance of your application. Let's take a look at how this one works.
Perhaps the most important thing to note is that although
@inlinable is related to code inlining, it's not the same as the
@inline attribute. We'll go through the concepts of
@inline before introducing
In programming, inline expansion, also called inlining, is a compiler optimization technique that replaces a method call with the body of the…
DispatchSource family of types from GCD contains a series of objects that are capable of monitoring OS-related events. In this article, we'll see how to use
DispatchSource to monitor a log file and create a debug-only view that shows the app's latest logs.
While every app will print debug logs to the developer console, it’s good practice to save these logs somewhere.
OSLog automatically saves your logs to the system, but I find that maintaining your own log file (like
MyApp-2020-11-24T14:23:42.log) is an additional good practice. If your app receives a bug report from an external beta tester, you…