Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion swiftui-expert-skill/references/state-management.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ struct GoodView: View {
}
```

### @StateObject instantiation in View's initializer
### @StateObject instantiation in View's initializer (if it's a Parent view)

This approach is an anti-pattern in general. Prefer storing the StateObject in the parent view or wherever the model is actually owned, then pass it down (use @ObservedObject, @EnvironmentObject, or @Bindable (for @Observable)) to keep ownership and lifecycle explicit.
If you need to create a @StateObject with initialization parameters in your view's custom initializer, be aware of redundant allocations and hidden side effects.

```swift
Expand Down