Thumbtack Jul 3, 2024

Swift Actor in Unit Tests

Article Summary

Abdul Moiz from Thumbtack reveals how Swift 6's concurrency checks broke their entire test suite. Their solution? A clever protocol-based pattern that makes actors mockable without sacrificing thread safety.

When Thumbtack's iOS team upgraded to Xcode 15.3, Swift's new concurrency warnings forced them to adopt actors for thread safety. But actors can't be subclassed, breaking their dependency injection and unit testing framework. The team developed a generalized solution using associated types that works across their entire codebase.

Key Takeaways

Critical Insight

Thumbtack created a reusable pattern using protocol associated types that lets teams adopt Swift actors while maintaining full unit test coverage.

The article includes complete code examples showing how the injection and stubbing mechanism works under the hood.

Recent from Thumbtack

Related Articles