Knowledgebase

SwiftUI Performance and Previews Print

  • mobiledevelopment, mobile, performance, themes, errors, troubleshooting, guide, howto
  • 0

Working efficiently.

WHAT PREVIEWS PROVIDE

Rendering views during development, without running the application.

WHAT THAT ENABLES

Seeing every state, size, theme and language quickly.

WHAT TO PREVIEW

Every state a view supports: default, loading, empty, error.

WHY

It is the fastest way to ensure they all exist and look correct.

WHAT MAKES PREVIEWS WORK

Views that receive their data rather than fetching it.

WHY THAT MATTERS

A view that fetches cannot be previewed meaningfully.

WHAT CAUSES PERFORMANCE PROBLEMS

Heavy work in the view body Views that invalidate more than necessary Non-lazy containers with many children Expensive computation on every update

WHAT TO DO

Move computation out of the body Use lazy containers for long content Provide stable identity

WHAT TO MEASURE WITH

The profiling instruments, and the framework's own diagnostics.

WHY MEASURE

Guessing about what updates is unreliable.

WHAT TO TEST ON

An older physical device.


Was this answer helpful?
Back

Are you happy with your experience? Leave us a review on Trustpilot.


Trustpilot