Overview
Enforce private access control for SwiftUI property wrappers that represent view-internal state.
Rule Identifier
private_property_wrappers
Rationale
SwiftUI property wrappers like @State, @StateObject, and @EnvironmentObject represent view-internal state that should not be accessed directly from outside the view. Making them private enforces proper encapsulation.
Property Wrappers That Should Be Private
@State - View's internal mutable state
@StateObject - View owns and manages the lifecycle
@EnvironmentObject - Injected from environment
@Environment - Reading from environment
@AppStorage - Persistent storage
@SceneStorage - Scene-specific storage
@FetchRequest - Core Data fetch
@GestureState - Gesture tracking state
@FocusState - Focus management
@ScaledMetric - Dynamic type scaling
Sometimes Non-Private (configurable)
@Binding - Often passed from parent view (public API)
@ObservedObject - Often passed from parent
Example
// ❌ Bad
@State var counter: Int = 0
// ✅ Good
private @State var counter: Int = 0
Configuration Options
Consider strictness levels:
- Strict: All property wrappers must be private
- Moderate: Allow @binding and @ObservedObject to be non-private
- Relaxed: Only enforce for state-owning wrappers
Priority
Medium - High value, low risk, moderate effort
Reference
Full spec in docs/TODO-private-property-wrappers.md (to be archived after issue creation)
Overview
Enforce
privateaccess control for SwiftUI property wrappers that represent view-internal state.Rule Identifier
private_property_wrappersRationale
SwiftUI property wrappers like
@State,@StateObject, and@EnvironmentObjectrepresent view-internal state that should not be accessed directly from outside the view. Making themprivateenforces proper encapsulation.Property Wrappers That Should Be Private
@State- View's internal mutable state@StateObject- View owns and manages the lifecycle@EnvironmentObject- Injected from environment@Environment- Reading from environment@AppStorage- Persistent storage@SceneStorage- Scene-specific storage@FetchRequest- Core Data fetch@GestureState- Gesture tracking state@FocusState- Focus management@ScaledMetric- Dynamic type scalingSometimes Non-Private (configurable)
@Binding- Often passed from parent view (public API)@ObservedObject- Often passed from parentExample
Configuration Options
Consider strictness levels:
Priority
Medium - High value, low risk, moderate effort
Reference
Full spec in
docs/TODO-private-property-wrappers.md(to be archived after issue creation)