0Pricing
SwiftUI Academy · Aula

Carregamento Preguiçoso de Conteúdo Pesado

Adie o trabalho dispendioso até que ele fique visível.

Carregamento Preguiçoso de Conteúdo Pesado é uma aula grátis de SwiftUI Academy no CoddyKit. Esta é a aula 3 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de SwiftUI Academy, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de SwiftUI Academy inclui 4 aulas no total.

Partes desta aula ainda não foram traduzidas e aparecem em inglês.

Build Only What Is Visible

Rendering a thousand off-screen rows is wasteful. Lazy containers build views only as they scroll into view, saving huge amounts of work.

Eager vs Lazy Stacks

A plain VStack builds every child up front. Inside a ScrollView with many items, that startup cost can freeze the screen.

Reach for LazyVStack

Swap in LazyVStack inside a ScrollView. It defers creating each row until that row is about to appear on screen.

ScrollView {
    LazyVStack {
        ForEach(items) { RowView(item: $0) }
    }
}

List Is Lazy Too

A List recycles rows automatically, much like a lazy stack. For long, simple feeds it is often the easiest fast choice.

Lazy Grids for Cards

For galleries, use LazyVGrid. It lays out cards in columns and only builds the cells currently in the viewport.

LazyVGrid(columns: cols) {
    ForEach(photos) { Thumb(photo: $0) }
}

Load Images Asynchronously

Heavy images should not block the main thread. AsyncImage fetches and decodes off-screen, showing a placeholder until ready.

AsyncImage(url: photo.url) { img in
    img.resizable()
} placeholder: { ProgressView() }

Downsample Big Images

A full-resolution photo in a small cell wastes memory. Downsample to the displayed size so scrolling stays smooth.

Defer Expensive Work

Compute heavy values when a row first appears, not for all rows at once. The onAppear hook lets you start that work just in time.

RowView(item: item)
    .onAppear { item.prefetch() }

Paginate Long Data

Do not load ten thousand records at once. Paginate: fetch the next page as the user nears the bottom of the list.

Lazy Has a Trade-off

Lazy views forget off-screen content, so building it again on scroll-back costs work. Keep each cell's body light to stay smooth.

Combine the Techniques

Real apps stack these: lazy containers, async images, and pagination together keep memory low and frames steady.

Quick Check

What is the main benefit of LazyVStack over VStack in a long scroll?

Recap: Lazy Loading

You learned to defer work with lazy containers, load images asynchronously, and paginate data so heavy content scrolls without stutter. 🚀

Perguntas Frequentes

A aula “Carregamento Preguiçoso de Conteúdo Pesado” é grátis?

Sim — o texto completo de “Carregamento Preguiçoso de Conteúdo Pesado” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de SwiftUI Academy, atualize para CoddyKit PRO. O curso de SwiftUI Academy inclui 4 aulas no total.

O que vou aprender em “Carregamento Preguiçoso de Conteúdo Pesado”?

Adie o trabalho dispendioso até que ele fique visível. Você pratica SwiftUI Academy com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.

Preciso ter experiência prévia para começar SwiftUI Academy?

Nenhuma experiência prévia é necessária. SwiftUI Academy no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 3 de 4.

Quanto tempo leva a aula “Carregamento Preguiçoso de Conteúdo Pesado”?

A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.

Posso escrever e executar código nesta aula de SwiftUI Academy?

Sim. Cada aula de SwiftUI Academy inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.

Todas as aulas deste curso

  1. Como o SwiftUI Recalcula as Visualizações
  2. Evitando Redesenhos Desnecessários
  3. Carregamento Preguiçoso de Conteúdo Pesado
  4. Analisando o Desempenho com Instruments
← Voltar para SwiftUI Academy