Sign in

Bruno Rocha
Person on desktop writing code
Photo by Lee Campbell on Unsplash

I gave a talk about scalable iOS apps at SwiftHeroes 2021 in which I speak about an app’s four “levels” of complexity, ending by stating that we still don’t know what the “fifth level” would be.

I do have one guess though: I believe a “level five” iOS app will be an app that contains so many modules and architectural components that any small addition will require writing massive amounts of boilerplate code. …


Violin strings
Photo by Belen Garrido on Unsplash

StaticString is an interesting type in Swift. It's essentially nothing more than a String that can't be modified for the purposes of referencing static content inside your binary.

You can encounter StaticString in Swift when referencing source metadata like #file and #function, but you can also define one yourself by explicitly declaring it in a string literal:

let path: StaticString = #file // StaticString
let myStaticString: StaticString = "SwiftRocks!"

In short, this is an optimization trick. A StaticString is meant to represent text that is known at compile-time (and is not going to be modified), allowing you to save memory…


A smartphone
Photo by David Grandmougin on Unsplash

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.

The Easy Case: Extending Basic Output 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…


Riding a BMX bike
Photo by Kvnga on Unsplash.

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…


Clapperboard
Photo by Jon Tyson on Unsplash.

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…


Taking a picture on phone
Photo by Suganth on Unsplash.

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:

  • Be running macOS 12 (this feature is not available in iOS).
  • Provide photographs of the object you want to capture.

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…


Skyscrapers
Photo by Drew Graham on Unsplash.

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.

What Is Thread Safety?

I personally define thread safety as a class’s ability to ensure “correctness” when multiple threads attempt to use it at the same…


License plate on a car
Photo by Thomas Millot on Unsplash.

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…


Bridge in the city
Photo by Will H McMahan on Unsplash.

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. …

Bruno Rocha

iOS Developer at Spotify | Writer of https://swiftrocks.com | Twitter: @rockbruno_

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