SwiftUI LazyVStack vs VStack

If we want to load the content into memory when we need it, we can use LazyVStack. It is particularly useful when we have large list of contents inside a scrollview.

Here’s how our regular VStack looks like:

VStack has 1000 Text content in it and the background color of VStack is blue:

And this is the memory report I have at first launch of my simulator:

Now back to LazyVStack:

Exactly same setup, I only replaced VStack with LazyVStack and here’s the result:

See that LazyVStack has flexible width and it covers all the screen whereas VStack fits in its context. With LazyVStack, in this example, we can scroll vertically by dragging anywhere on the screen.

And the memory report at first launch of my simulator:

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store