Skip to content
Back to skills

Ios Swiftui

ASecurity

On iOS 17+, the rule of thumb depends on whether your view model uses the new `@Observable` system or the older `ObservableObject` pattern. If your view model is `@Observable`: - Use `@State` when the view owns and creates the view model. - Use a plain stored property like `let viewModel: MyViewModel` when the parent passes it in. - Do not use `@ObservedObject` or `@StateObject` for new `@Observable` models. Example: ```swift @Observable final class ProfileViewModel { var name = "Huy" } struc...

  • 584 stars
  • 0 votes
  • 0 copies
  • 4 views
  • Added September 5, 2026
developmentswift

Security analysis

A100/100

Pro scans all 12 files and shows the line behind each finding

Scanned September 5, 2026

npx -y skills add HoangNguyen0403/agent-skills-standard --skill ios-swiftui --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Ios Swiftui?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Ios Swiftui
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/hoangnguyen0403-ios-swiftui-agent-skills-standard/badge)](https://www.skillsdirectory.com/skills/hoangnguyen0403-ios-swiftui-agent-skills-standard)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
On iOS 17+, the rule of thumb depends on whether your view model uses the new `@Observable` system or the older `ObservableObject` pattern.

If your view model is `@Observable`:

- Use `@State` when the view owns and creates the view model.
- Use a plain stored property like `let viewModel: MyViewModel` when the parent passes it in.
- Do not use `@ObservedObject` or `@StateObject` for new `@Observable` models.

Example:

```swift
@Observable
final class ProfileViewModel {
    var name = "Huy"
}

struct ProfileView: View {
    @State private var viewModel = ProfileViewModel()

    var body: some View {
        Text(viewModel.name)
    }
}
```

If a child receives that same `@Observable` model:

```swift
struct ProfileNameView: View {
    let viewModel: ProfileViewModel

    var body: some View {
        Text(viewModel.name)
    }
}
```

If your view model is still using legacy `ObservableObject`:

- Use `@StateObject` when the view owns and creates it.
- Use `@ObservedObject` when the model is created elsewhere and injected into the view.

Example:

```swift
final class ProfileViewModel: ObservableObject {
    @Published var name = "Huy"
}

struct ProfileView: View {
    @StateObject private var viewModel = ProfileViewModel()

    var body: some View {
        Text(viewModel.name)
    }
}

struct ProfileNameView: View {
    @ObservedObject var viewModel: ProfileViewModel

    var body: some View {
        Text(viewModel.name)
    }
}
```

Short version:

- `@State`: local value state, and owned `@Observable` view models on iOS 17+
- `@StateObject`: owned legacy `ObservableObject` view models
- `@ObservedObject`: injected legacy `ObservableObject` view models

For new iOS 17+ code, prefer `@Observable` + `@State` in the owning view.

Files in this skill

  • eval-1.baseline.md944 B
  • eval-1.with-skill.md1.7 KB
  • eval-2.baseline.md566 B
  • eval-2.with-skill.md1.1 KB
  • eval-3.baseline.md471 B
  • eval-3.with-skill.md558 B
  • trigger-1.md183 B
  • trigger-2.md148 B
  • trigger-3.md111 B
  • trigger-4.md136 B
  • trigger-5.md180 B

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.