New SwiftUI Features for the next step of iOS development
Tags: swift, ios, flutter, mobile
Published: 2021-09-23 11:00:47

**New SwiftUI Features for the next step iOS development:**

**1. Runs on Apple’s Latest OS**

Before getting into the features of SwiftUI, the first thing to know is SwiftUI is not compatible with former versions of Apple’s operating system. It only supports iOS 13, the iOS 13 is just in Xcode 11, and Xcode 11 is not released yet so we have to install Xcode 11 Beta for now. It means you cannot use SwiftUI if your application requires to support of iOS version 12 or its previous versions.

**2. No Auto Layout**

Auto Layout has been the preferred way of layouts declaration on Apple platforms as it encourages developers to keep some assumptions about the container’s actual dimensions and it makes UIs more flexible. However, SwiftUI replaces Auto Layout with layout constructs – one level higher. It works similar to how the layout has been handled in WatchOS.

**3. Doesn’t support Storyboard**

SwiftUI also replaces storyboards with code; thereby it becomes easy to make a reusable view. Developers often get code conflict problems when using storyboards in the development team. SwiftUI avoids the issue and empowers developers to freely decide whether they like to work visually or directly in code while making the code the “single source of truth”.

**4. Dark Mode**

Similarly, SwiftUI has changed the typical bright theme into a darker mode that can be easily visible particularly at night. Some users think a brighter theme looks better. It did nothing but enabled developers to add a dark theme to their apps if they are not comfortable with the brighter ones.
 
**5. Empowers systems to do their tasks**

With SwiftUI, your app can automatically translate its view into a visual interface element suitable for the given platform.

For example, the Toggle view can render differently and correctly on macOS, iOS, watchOS, and tvOS. Moreover, SwiftUI can adjust the colors, padding, and spacing based on the platform, container size on the control state and the current screen. Paragraph text padding, for example, appears in one way on iOS and inclines more border space on the iPad’s screen.
 
As such, with iOS, you are not only writing less code but also leaving everything to the system to do its tasks and results in only a few bugs as well.

**6. Cross-platform User Interface**

SwiftUI does not stop there it also serving as a cross-platform user interface layer, which functions across tvOS, macOS, iOS and watchOS. It is easier to use the same code across all platforms. To a certain extent, you no need to take your business logic, API code, and Models from platform to platform and you can also use most of your UI elements across all platforms. Hence, now it is enough to learn one layout framework and one language and can deploy the code anywhere.

**7. View Composition**

The main concept that was repeated in the SwiftUI sessions at WWDC is its views. Views in SwiftUI are extremely lightweight and it includes zero performance penalties while creating them. Unlike UIViews, most SwiftUI views are available as a Swift struct and can be created, referenced and passed as value parameters. The use of Swift struct eliminates the excess of memory allocations and the development of several subclasses & dynamic messages - the shortcomings of passing UIkit based UIViews.

Further, the modifiers and parameters on a nested SwiftUI view can be composited together as a single entity at the time of display and layout cycles. Besides, the nodes present in the view tree are tracked for state changes and if there is no change, no need to be rendered.

All these convey that in SwiftUI, it is a distinct advantage to build many special-purpose views based on your app requirement. Here is a code sample for view composition:
 
In the above code, a MultiLineText view would be used throughout an app.

 
**8. Simplifies adding animations**

With SwiftUI, creating animations becomes as simple as adding a single method call. It can calculate and animate transitions automatically when required. 

**9. Live Preview**
When you use SwiftUI in Xcode, you can design, build as well as test your application interface even without running your app. 

I Design tools of Xcode 11 allow drag & drop UI building with SwiftUI. The changes you made in the UI are visible in the preview screen. Finally, Xcode recompiles your changes and sets them into a working version of your app.

10. Semantic Colors
SwiftUI provides standard colors like green, blue and red. However, those are not the pure colors as like from UIColor. The colors can automatically adapt to dark and light mode – they will appear darker or brighter based on the system appearance.

Right now, the vast majority of iOS applications are developed using UIKit. Industry experts expect the iOS community will migrate over to SwiftUI at any kind of rapid pace. There are still many other features from SwiftUI that must be explored.