Number: 040, Date: 2024-10-14

2024.10.07 ~ 2024.10.13

✅ Swift Testing


Starting from Swift 6, a convenient Swift Testing framework has been introduced for testing code.

To explore its capabilities, I migrated my existing test code, which was written using the XCTest framework, to Swift Testing.

Key features applied:

  1. All assertion functions for checking result values have been unified under the #expect macro, making them clearer and easier to use.
  2. When using the async and await syntax for networking code, there’s no need for the old wait-time configurations.
  3. Simply adding @Test to a test function makes it recognizable as a test, and it allows passing multiple arguments as an array, along with various other options.

Apple also provides the 🔗 Migrating a test from XCTest guide, and since Swift Testing is the default UnitTest framework when creating a new project, it seems recommended to use it.

🌎 async ~ await


I reviewed the async and await syntax, one of the Swift Concurrency features introduced in Swift 5.5.

Traditionally, asynchronous code could be written using completion handlers, DispatchQueue, RxSwift, Combine, etc. The async and await syntax helps write asynchronous code in a synchronous-like manner.

Benefits of using async & await:

  1. Improved readability – Since the asynchronous code is written as if it’s synchronous, it avoids callback hell.
  2. Easier error handling – When used with the throw keyword, error handling becomes simpler.
  3. Prevents mistakes – It prevents the common mistake of forgetting to call the completion handler.
  4. Easier testing – It works seamlessly with Swift Testing, making it easier to write test code.

🙋🏻‍♂️ Other Notes


  1. Tip: It’s crucial to monitor the costs of development services (e.g., reasons for being charged for unused services, cost breakdowns, history, etc.).
  2. I have a basic diary app on iOS, but it doesn’t have a sharing function, so I should try to implement an app that can be shared with SwiftUI.