LazyVStack y LazyHStack
Renderice contenido extenso de forma diferida para mejorar el rendimiento.
LazyVStack y LazyHStack es una lección gratuita de SwiftUI Academy en CoddyKit. Esta es la lección 2 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de SwiftUI Academy, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de SwiftUI Academy incluye 4 lecciones en total.
Partes de esta lección aún no han sido traducidas y se muestran en inglés.
The Eager Problem
A regular VStack builds every child at once. With hundreds of rows, that eager work can stutter and waste memory.
Meet LazyVStack
A LazyVStack only creates rows as they scroll into view, keeping huge lists fast and light. ⚡
LazyVStack {
ForEach(items) { item in
Row(item)
}
}Lazy Needs Scrolling
Always place a LazyVStack inside a ScrollView, since lazy loading only pays off when content scrolls offscreen.
ScrollView {
LazyVStack {
ForEach(items) { Row($0) }
}
}The Horizontal Twin
A LazyHStack does the same trick sideways, perfect for long, swipeable rows of cards or thumbnails.
ScrollView(.horizontal) {
LazyHStack {
ForEach(photos) { Thumb($0) }
}
}Same Spacing API
Lazy stacks accept the same spacing and alignment options as their eager cousins, so your layout code barely changes.
LazyVStack(alignment: .leading, spacing: 12) {
ForEach(items) { Row($0) }
}Cells Get Reused
As rows leave the screen, a LazyVStack can discard them, so memory stays steady even with thousands of items.
Lazy vs List
A List is lazy too, but a LazyVStack gives you styling freedom with no built-in separators or insets.
Pinned Headers
Lazy stacks support pinnedViews, letting section headers stick to the top as you scroll, like a contacts app.
LazyVStack(pinnedViews: [.sectionHeaders]) {
Section(header: Header()) {
Rows()
}
}When to Stay Eager
For a handful of items a plain VStack is simpler. Reach for lazy only when the list grows long.
Watch the Scroll
You will not see new LazyVStack rows being built, but Instruments shows they appear just in time as you scroll.
Scale with Confidence
With lazy stacks you can show endless feeds, galleries, and timelines without ever worrying about performance. ✨
Quick Check
Think about why lazy stacks exist.
Recap
You met LazyVStack and LazyHStack: stacks that create children on demand inside a ScrollView for smooth, large layouts. 🎉
Preguntas frecuentes
¿La lección «LazyVStack y LazyHStack» es gratis?
Sí — el texto completo de «LazyVStack y LazyHStack» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de SwiftUI Academy, actualiza a CoddyKit PRO. El curso de SwiftUI Academy incluye 4 lecciones en total.
¿Qué aprenderé en «LazyVStack y LazyHStack»?
Renderice contenido extenso de forma diferida para mejorar el rendimiento. Practicas SwiftUI Academy con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.
¿Necesito experiencia previa para empezar SwiftUI Academy?
No se requiere experiencia previa. SwiftUI Academy en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 2 de 4.
¿Cuánto tiempo toma la lección «LazyVStack y LazyHStack»?
La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.
¿Puedo escribir y ejecutar código en esta lección de SwiftUI Academy?
Sí. Cada lección de SwiftUI Academy incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.
Todas las lecciones de este curso
- ScrollView horizontal y vertical
- LazyVStack y LazyHStack
- Grids adaptativas con LazyVGrid
- ScrollView Reader y anchors