2 min read

Issue #46

Hi there,
welcome to the 46th issue of the newsletter! Today among other things I'm summarizing the updates in Xcode and Swift that affect code and project quality. Hope you enjoy the reading 😊

Iterating over some elements

Here's how to iterate over only some elements in the array. Both options, for-case-let and for-in-if, are more efficient than filtering the array and iterating on the filtered results 🙌

Xcode 14.3 & Swift 5.8

There's a bunch of improvements available in the new Swift and Xcode. Here are a few things that caught my attention:

Implicit self

  • Implicit self is now permitted for weak self captures, after self is unwrapped:
class ViewController {
  let button: Button

  func setup() {
      button.tapHandler = { [weak self] in
          guard let self else { return }
          dismiss() // refers to `self.dismiss()`
      }
  }

  func dismiss() { ... }
}

Debugging previews with print

  • print output now appears in the console for SwiftUI Previews by selecting “Preview” tab in the console.

Previews in modular dependencies

  • Fixed: Previews can fail when previewing a file inside of a Swift package target that is the dependency of an executable target.

Waiting for expectations

  • The timeout argument of XCTestCase.wait(for:timeout:enforceOrder:) and related methods is now optional—if you don’t specify it, the function waits indefinitely (until the overall test times out.) To ensure reasonable execution time, set an appropriate value for the executionTimeAllowance property of the running XCTestCase instance (self).
  • XCTestCase.wait(for:timeout:enforceOrder:) and related methods are now marked unavailable in concurrent Swift functions because they can cause a test to deadlock. Instead, you can use the new concurrency-safe XCTestCase.fulfillment(of:timeout:enforceOrder:) method.

Test plans


Read about everything new here (this links directly to the section about Swift but you can scroll up and down to read about all the changes in Xcode):

Xcode 14.3 Release Notes | Apple Developer Documentation
Update your apps to use new features, and test your apps against API changes.

✌️
Alright, that's it for today.
I'm curious if you found one of the tips particularly interesting - let me know by replying to this email!