8.8 · Preference keys and coordinate spaces

Environment values flow down the tree. Preferences flow up, which is how a child tells its ancestors about itself without a binding.

Mental model. Environment goes down, preferences go up. And every position you read is relative to some coordinate space; say which.

Talking upward

Preference keys and the reduce step.

  1. What is a PreferenceKey, and how do values travel from children up to ancestors? 8.8.1 · L5
    A PreferenceKey is the upward counterpart of the environment. A child publishes a value with .preference(key: MyKey.self, value: x), and an ancestor reads the…

Measuring

Named coordinate spaces and frames.

  1. What are the coordinate spaces in SwiftUI, and how do you read a view’s frame? 8.8.2 · L3
    Every position or frame is meaningful only relative to a coordinate space. SwiftUI has three kinds. .local is the view’s own space, with the origin at its…

More in SwiftUI