What's new in Xcode 13 beta 5

Xcode 13 beta 5 has just been released: let's have a look at what's new in SwiftUI!

Interactive shapes with ContentShapeKinds

Button("Hover me") {}
  .hoverEffect(.lift)
  .contentShape(.hoverEffect, Circle())

Text("Open Menu")
  .contextMenu {
    Button(...) { ... }
    Button(...) { ... }
  }
  .contentShape(.contextMenuPreview, Circle())

A new contentShape(_:_:eofill:) modifier has been introduced, letting us further define the shape of our interactive elements in special situations:

extension View
  @inlinable public func contentShape<S: Shape>(
    _ kind: ContentShapeKinds,
    _ shape: S,
    eoFill: Bool = false
  ) -> some View
}

ContentShapeKinds is a new option set with the following values:

@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
public struct ContentShapeKinds : OptionSet {
  public static let interaction: ContentShapeKinds
  public static let dragPreview: ContentShapeKinds
  public static let contextMenuPreview: ContentShapeKinds
  public static let hoverEffect: ContentShapeKinds
}

iOS 15b5 simulator crashes when showing a context menu, FB9486120.

Custom links handling

VStack {
  Link("Visit Five Stars", destination: URL(string: "https://fivestars.blog")!)
  Text("Visit [Five Stars](https://fivestars.blog) for more SwiftUI.")
}
.environment(\.openURL, OpenURLAction { url in
  // do something here...
  return .handled
})

Links and links within Text can now trigger custom actions. The default (and previous) behavior is for these links to open the associated URL on the device's browser. Now it's up to apps to decide what to do.

The custom behavior is possible by setting the openURL environment value.

Here are the possible outcomes we can return when a link is tapped:

public struct OpenURLAction.Result {
  /// The URL was handled (by the app).
  public static let handled: OpenURLAction.Result

  /// Action was ignored.
  public static let discarded: OpenURLAction.Result

  /// The original URL should be handled by the system (default behavior, opens browser with original URL).
  public static let systemAction: OpenURLAction.Result

  /// The given URL should be handled by the system (opens browser with the given URL).
  public static func systemAction(_ url: URL) -> OpenURLAction.Result
}

Opening a URL via Link view on iOS 15b5 simulator crashes very often, FB9486139.

More binding options

Following SE-0293 and List new binding capabilities, now also hierarchy Lists and OutlineGroups accept binding parameters:

struct FileItem: Identifiable {
  var name: String
  var children: [FileItem]?

  var id: String { name }

  static let spmData: [FileItem] = [
    FileItem(name: ".gitignore"),
    FileItem(name: "Package.swift"),
    FileItem(name: "README.md"),
    FileItem(name: "Sources", children: [
      FileItem(name: "fivestars", children: [
        FileItem(name: "main.swift")
      ])
    ])
  ]
}

struct ContentView: View {
  @State var data: [FileItem] = FileItem.spmData

  var body: some View {
    List($data, children: \.children) { $item in // 👈🏻
      TextField("Name", text: $item.name)
    }
  }
}

Making a few changes to the children values in the example above crashes the app, FB9486151.

Task priorities

We have a new task(priority:_:) view modifier letting us specify the priority to use when creating the given task. The previous modifier (without priority parameter) has been removed.

From:

.task {
  ...
}

To:

.task(priority: .high) {
  ...
}

AnimatableModifier deprecation

The AnimatableModifier protocol has been deprecated, instead we can make our modifiers conform to both Animatable and ViewModifier.

From:

struct FSAnimationEffect: AnimatableModifier { // 👈🏻
  var animatableData: CGFloat { ... }

  func body(content: Content) -> some View {
    ...
  }
}

To:

struct FSAnimationEffect: ViewModifier, Animatable { // 👈🏻
  var animatableData: CGFloat { ... }

  func body(content: Content) -> some View {
    ...
  }
}

Documentation

We have a new documentation for:

Conclusions

Did you find anything else interesting in Xcode 13 beta 5? Please let me know!

We should have at least one more Xcode beta seed before the release candidate: don't forget to report any issue you find to Apple!

This article is part of a series exploring new SwiftUI features. We will cover many more during the rest of the summer: subscribe to Five Stars's feed RSS or follow @FiveStarsBlog on Twitter to never miss new content!

⭑⭑⭑⭑⭑

Further Reading

Explore SwiftUI

Browse all