0Pricing
SwiftUI Academy · درس

التحميل الكسول للمحتوى الثقيل

أجّل العمليات المكلفة حتى يصبح المحتوى مرئيًا

التحميل الكسول للمحتوى الثقيل درس مجاني في SwiftUI Academy على CoddyKit. هذا هو الدرس 3 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في SwiftUI Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة SwiftUI Academy 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

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. 🚀

الأسئلة الشائعة

هل درس «التحميل الكسول للمحتوى الثقيل» مجاني؟

نعم — نص درس «التحميل الكسول للمحتوى الثقيل» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة SwiftUI Academy، انتقل إلى CoddyKit PRO. تتضمن دورة SwiftUI Academy 4 دروس في المجموع.

ماذا ستتعلم في «التحميل الكسول للمحتوى الثقيل»؟

أجّل العمليات المكلفة حتى يصبح المحتوى مرئيًا تتمرن على SwiftUI Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ SwiftUI Academy؟

لا تُشترط خبرة سابقة. SwiftUI Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 3 من أصل 4.

كم من الوقت يستغرق درس «التحميل الكسول للمحتوى الثقيل»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس SwiftUI Academy هذا؟

نعم. كل درس في SwiftUI Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. كيف تعيد SwiftUI حساب الواجهات
  2. تجنب إعادة الرسم غير الضرورية
  3. التحميل الكسول للمحتوى الثقيل
  4. تحليل الأداء باستخدام Instruments
← العودة إلى SwiftUI Academy