modern-swift

modern-swift is a cursor rule for coding agents from roy2392/vibe-agents-rules. It costs 942 tokens per session, scanned A, a copy of modern-swift, MIT.

SwiftUI coding guidance for building Apple-platform interfaces with Swift, using Apple's current patterns for screen state, shared data, and asynchronous work.

In plain words
What is it for?
Use it when creating or reviewing SwiftUI views, managing local or shared state, connecting screens, or adding asynchronous tasks.
Why use it?
It helps avoid older UIKit-style approaches and confusing data flow, so SwiftUI code stays consistent with how the framework is designed.

Cursor rule

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/roy2392/vibe-agents-rules/modern-swift
Clone the repo
git clone --depth 1 https://github.com/roy2392/vibe-agents-rules

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for modern-swift

README.md
[![agentmods](https://agentmods.dev/badge/rules/roy2392/vibe-agents-rules/modern-swift.svg)](https://agentmods.dev/rules/roy2392/vibe-agents-rules/modern-swift)
Your own site
<a href="https://agentmods.dev/rules/roy2392/vibe-agents-rules/modern-swift"><img src="https://agentmods.dev/badge/rules/roy2392/vibe-agents-rules/modern-swift.svg" alt="Measured on agentmods" height="20"></a>
Per session 942 This file is loaded in full into every session.
When invoked 942 The same file — it is already loaded in full.
Security scan A 0 findings. Scan, not verified.
Origin 100% copy Near-identical to another mod in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00942 $0.00942
Opus 5 $0.00471 $0.00471
Sonnet 5 $0.00188 $0.00188
Haiku 4.5 $0.00094 $0.00094

Measured 5d ago against content hash c0cb592cb57e, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-05, from the pricing page.

Security

Grade A, and why

modern-swift scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 5d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

Origin

This is a copy

100% identical to modern-swift — 0 lines differ, which has more behind it and is treated as the original. This page carries a canonical link to it rather than competing with it.

project-rules/modern-swift.mdc · 165 lines

How it starts

The opening of the file, as written. The whole thing — 165 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Modern Swift Development

Write idiomatic SwiftUI code following Apple's latest architectural recommendations and best practices.

Core Philosophy

  • SwiftUI is the default UI paradigm for Apple platforms - embrace its declarative nature
  • Avoid legacy UIKit patterns and unnecessary abstractions
  • Focus on simplicity, clarity, and native data flow
  • Let SwiftUI handle the complexity - don't fight the framework

Architecture Guidelines

1. Embrace Native State Management

Use SwiftUI's built-in property wrappers appropriately:

  • @State - Local, ephemeral view state
  • @Binding - Two-way data flow between views
  • @Observable - Shared state (iOS 17+)
  • @ObservableObject - Legacy shared state (pre-iOS 17)
  • @Environment - Dependency injection for app-wide concerns

2. State Ownership Principles

  • Views own their local state unless sharing is required
  • State flows down, actions flow up
  • Keep state as close to where it's used as possible
  • Extract shared state only when multiple views need it

3. Modern Async Patterns

  • Use async/await as the default for asynchronous operations
  • Leverage .task modifier for lifecycle-aware async work
  • Avoid Combine unless absolutely necessary
  • Handle errors gracefully with try/catch

4. View Composition

  • Build UI with small, focused views
  • Extract reusable components naturally
  • Use view modifiers to encapsulate common styling
  • Prefer composition over inheritance

5. Code Organization

  • Organize by feature, not by type (avoid Views/, Models/, ViewModels/ folders)
  • Keep related code together in the same file when appropriate
  • Use extensions to organize large files
  • Follow Swift naming conventions consistently

Implementation Patterns

Simple State Example

struct CounterView: View {
    @State private var count = 0
    
    var body: some View {
        VStack {
            Text("Count: \(count)")
            Button("Increment") { 
                count += 1 
            }
        }
    }
}

Read the full file on GitHub · 165 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 5d ago First seen · 165 lines · 942 tokens per session scan A c0cb592cb57e

Subscribe to this mod's changes

modern-swift is a cursor rule published in the GitHub repository roy2392/vibe-agents-rules (11 stars, last pushed 1y ago), licensed MIT. It adds 942 tokens to every session, about $0.0047 per session on Opus 5. A static security scan graded it A with 0 findings. It is 100% identical to modern-swift, differing in 0 lines, and is treated as a copy.