What is new on ios 18 in terms of swiftui?

Generated on 7/30/2024

1 search

Tailscan

This post is brought to you by Tailscan, the best devtool for Tailwind CSS.

In iOS 18, there are several new features and improvements in SwiftUI:

  1. New TabView Syntax: SwiftUI introduces a new syntax for TabView to make it easier to catch common errors at build time. You now declare a tab struct with a title, image, and its content view. Optionally, you can include a selection value in the tab to enable programmatic selection. This ensures that all tabs have the same selection type and that the type matches the TabView itself. (Elevate your tab and sidebar experience in iPadOS)

  2. Graphics Capabilities: SwiftUI now allows you to mix colors beautifully with a new mix modifier on Color, which blends it with another color by a given amount. Additionally, custom shaders can now be precompiled to avoid frame drops caused by lazy shader compilation. (What’s new in SwiftUI)

  3. Scroll View Enhancements: There are new APIs for fine-grained control over scroll views. You can now react to changes in content offsets, content size, and more with onScrollGeometryChange. This allows for features like auto-playing videos when a view's visibility changes due to scrolling. (What’s new in SwiftUI)

  4. Improved Interoperability: SwiftUI has enhanced its interoperability with UIKit and AppKit. Gesture recognition has been factored out of UIKit, allowing you to use any built-in or custom UI gesture recognizer in your SwiftUI view hierarchy. Animations have also been factored out, enabling you to set up animations on UIKit or AppKit views and drive them with SwiftUI, including fully custom animations. (Platforms State of the Union)

  5. Custom Containers and Mesh Gradients: SwiftUI introduces custom containers and mesh gradients, providing more tools for creating immersive experiences. (Platforms State of the Union)

  6. Main Actor Isolation: The new Swift 6 language mode enables compile-time data race safety. Views in SwiftUI are now evaluated on the main actor, and the View protocol is marked with the @MainActor annotation, meaning all types conforming to View are implicitly isolated to the main actor by default. (What’s new in SwiftUI)

These updates make SwiftUI more powerful and easier to use, allowing developers to create more dynamic and responsive user interfaces.