Skip to content

[Swift6]: Use @State over @StateObject in ViewContext #142

@ra1028

Description

@ra1028

Checklist

  • Reviewed the README and documentation.
  • Checked existing issues & PRs to ensure not duplicated.

Description

@StateObject is slightly less performant than @State due to the overhead of resubscribing the subtree's ObservableObjects when updating the parent view.
However, Swift5's actor isolation inference seems to have a special behavior when using @StateObject (views that depend on @ViewContext indirectly through other dynamic properties are not isolated to the main actor), and I found out that it breaks backward compatibility.
Most likely it's a bug, but fortunately the actor isolation inference for property wrapper will be removed in Swift6, so then we can replace state management using @StateObject with @State.

Example Use Case

N/A

Alternative Solution

No response

Proposed Solution

No response

Motivation & Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions