

Because LazyVStack takes entire width provided by the parent, alignment is more apparent. I don’t think it’s hyperbolic to describe SwiftUI as a game changer for anyone building apps on Apple’s platforms. Just like VStack, LazyVStack supports alignment for child views with just a little difference. With the above in place, we can now move on to implementing ArticleDetailView and the other top-level components that our app needs - each completely self-contained and isolated, and each automatically reusable in many different kinds of situations. While I’ll cover all of those new features in great detail in upcoming articles on Swift by Sundell - let’s take a look at how they let us express View implementations in a very nice and concise way: struct WelcomeView: View.
#Swiftui vstack top alignment code
In their own code samples, Apple makes heavy use of several new Swift 5.1 features, for example the new “DSL-like” syntax - which allows return statements to be omitted - and the new some keyword, which enables a protocol with associated types to be used as a return type. That’s really important in terms of the API’s design, since it makes the whole system completely recursive - as views can easily be embedded inside of other views. In SwiftUI, a component is simply called a view, and is defined through the View protocol - which only has a single property requirement, a body - which interestingly is also, in turn, a View.

#Swiftui vstack top alignment series
One key aspect of most declarative UI frameworks is that they aim to boil any kind of UI down into a series of components - which can then be combined and composed in order to form different sets of views, animations, and interactions. While there’s a ton of functionality to be discovered and experimented with in this new UI framework for all of Apple’s platforms - let’s start by taking a first look at some of the fundamentals of SwiftUI, and how it lets us drastically reduce the amount of code needed to produce common forms of UIs and interactions. It’s therefore especially exciting to see Apple step into this scene, with their own, completely native declarative UI framework - called SwiftUI. On the web with frameworks like React and Vue.js, in cross-platform development environments like React Native and Flutter, and through native tools like RxSwift and RxCocoa - declarative UIs and the reactive principles behind them have truly taken many development communities by storm.

Declarative UI programming patterns have become incredibly popular over the last few years.
