What's new in Xcode 13.2 beta 2

This second beta brought us a very cool new build mode for the Swift compiler. Enable it via command line:

defaults write com.apple.dt.XCBuild EnableSwiftBuildSystemIntegration 1

It's a very light update for SwiftUI. Let's see what's new.

TextField and SecureField

Both TextField and SecureField come with many initializers: instead of having parameters with default values, those views now have different overloads, either requiring or omitting such parameters.

For example we went from:

extension TextField where Label == Text {
  public init<S>(_ title: S, text: Binding<String>, prompt: Text? = nil) where S : StringProtocol
}

to:

extension TextField where Label == Text {
  public init<S>(_ title: S, text: Binding<String>, prompt: Text?) where S : StringProtocol
  public init<S>(_ title: S, text: Binding<String>) where S : StringProtocol
}

This change spans all TextField/SecureField overloads, is completely seamless for third-party developers, and is back-ported all the way to iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0.

This back-port is possible thanks to @_alwaysEmitIntoClient, which we covered here.

For example, if we take a look at SwiftUI's Swift Interface, we will see the implementation of the second initializer (from above):

extension TextField where Label == Text {
  @_alwaysEmitIntoClient @_disfavoredOverload 
  public init<S>(_ title: S, text: Binding<String>) where S : StringProtocol {
    self.init(title, text: text, onCommit: {})
  }
}

...while the first initializer just dropped the default value:

// From:
public init<S>(_ title: S, text: Binding<String>, prompt: Text? = nil) where S : StringProtocol

// To:
public init<S>(_ title: S, text: Binding<String>, prompt: Text?) where S : StringProtocol

All these new initializers, which are compatible with earlier OSes, come with the same documentation as the original initializers with the "extra" parameter, complete with mentions of:

  • prompt parameter
  • Focus API
  • View.onSubmit view modifier

It's most likely an oversight, but it'd be great if this were a hint that a back-port of those features is on the way.

Conclusions

Did you find anything else interesting in Xcode 13.2 beta 2? Please let me know!

⭑⭑⭑⭑⭑

Further Reading

Explore SwiftUI

Browse all