NEW Tool! SwiftFairy: Local Swift and SwiftUI code reviews for your coding agent. Learn more ...NEW Tool! SwiftFairy:Local code reviews for your agents. Learn more...
← All SwiftFairy Scrolls

SwiftFairy Scroll

Performant Swift Charts

Improve rendering and interaction performance by structuring charts and surrounding views to limit unnecessary updates and use Swift Charts APIs effectively.

What your agent can improve

Chart structure

Help your agent structure charts and surrounding views to avoid updates that do not affect the chart.

Rendering performance

Identify API choices that introduce unnecessary rendering work and give your agent guidance to address them.

Responsive interactions

Find interaction state changes that trigger unnecessary chart updates, helping your agent keep interactions responsive.

Issues Performant Swift Charts flags

Performant Swift Charts flags over 70 issues in your code. Each finding arrives at the line where the issue occurs, with the guidance and code example written for that case.

  • Missing measurements replaced with zero
  • Lines and areas without series identity or a defined order
  • A Chart built inside a larger view body instead of a dedicated view
  • Selection state that re-evaluates the whole chart
  • Selection resolved by scanning the plotted data
  • Value labels that change per observation
  • Per-mark work repeated inside chart content
  • Bars on a date or number axis without a unit or bins
  • @Environment read inside custom ChartContent
  • A parent's animation reaching the chart
Alone SwiftFairy

Token efficiency

Your agent skips millions of tokens of reasoning and reads guidance only for the issues flagged.

Cross-file insight

Follows your view hierarchy across files and presentations, beyond single views and functions.

Deep knowledge

Built on our books and articles, and Natalia's work on Apple's SwiftUI team.

Example findings

These examples show the patterns SwiftFairy flags and the guidance your agent can use to address them. Highlighted lines mark the code to review; each finding indicates whether the guidance is a requirement, recommendation, or consideration.

Consider

Preserve missing-data semantics

When a measurement is missing, substituting zero changes what the chart communicates. The appropriate representation depends on whether the chart draws independent marks or connects neighboring observations.

Pattern flagged for review

BarMark(
     x: .value("Date", reading.date),
     y: .value(
         "Temperature",
         reading.temperature ?? 0
     )
)

AreaMark(
     x: .value("Date", reading.date),
     y: .value(
         "Temperature",
         reading.temperature ?? 0
     )
)

A possible improvement

if let temperature = reading.temperature {
     BarMark(
         x: .value("Date", reading.date),
         y: .value(
             "Temperature",
             temperature
         )
     )
}

AreaMark(
     x: .value("Date", reading.date),
     y: .value(
         "Temperature",
         reading.temperature ?? Double.nan
     )
)

For independent bars, omit the mark when its measurement is missing. For an area chart, retain the observation and use Double.nan for the missing value to break the area across the gap. Removing the observation would connect its neighbors.

Consider

Use consistent semantic labels

When observations represent the same variable, their semantic label should remain consistent. Each observation's value belongs in the second argument to .value, rather than being interpolated into its label.

Pattern flagged for review

BarMark(
     x: .value("Date", reading.date),
     y: .value("Temperature", reading.temperature)
)
.foregroundStyle(by:
    .value(
      "Status \(reading.status)",
      reading.status
    )
)

A possible improvement

.foregroundStyle(
     by: .value("Status", reading.status)
)

Use a consistent dimension label and pass the observation's status as the value. Whether a dynamic label is appropriate depends on the intended semantics.

…and over 70 other issues.

Put the findings to work

Ask your agent to review a code change or a complete codebase with SwiftFairy. Your agent uses the findings and their accompanying code examples to resolve issues in your code.

How to use SwiftFairy

Try Performant Swift Charts free for one day

Activate your free trial within the app at any time.

Choose lifetime access, a fixed term, or a subscription for this Scroll, or get all four together in a bundle.

Explore the other Scrolls