mvvm-architecture

mvvm-architecture is a cursor rule for Cursor from moasq/ios-dev-agent. It costs 1,248 tokens per session, scanned A, original, MIT.

A set of rules for structuring SwiftUI apps with MVVM, a pattern that separates screen data and actions from the user interface. It also defines a shared state type for loading, success, and failure.

In plain words
What is it for?
Use it when organizing view models, async data loading, search state, and other SwiftUI screen logic.
Why use it?
It gives asynchronous operations a consistent way to represent their current state instead of scattering separate loading and error variables through the app.

Cursor rule for Cursor

Written for Cursor: installed under .cursor/. Also seen: positional $N argument.

Good fit Use it when organizing view models, async data loading, search state, and other SwiftUI screen logic.

Compare 6 cursor rules from other repositories ↓
Install with agentmods
npx agentmods add rules/moasq/ios-dev-agent/mvvm-architecture
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.

Clone the repo
git clone --depth 1 https://github.com/moasq/ios-dev-agent

Made for: Cursor.

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 mvvm-architecture

README.md
[![agentmods](https://agentmods.dev/badge/rules/moasq/ios-dev-agent/mvvm-architecture/github.svg)](https://agentmods.dev/rules/moasq/ios-dev-agent/mvvm-architecture)
Your own site
<a href="https://agentmods.dev/rules/moasq/ios-dev-agent/mvvm-architecture"><img src="https://agentmods.dev/badge/rules/moasq/ios-dev-agent/mvvm-architecture/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for mvvm-architecture

Your own site · 80×15
<a href="https://agentmods.dev/rules/moasq/ios-dev-agent/mvvm-architecture"><img src="https://agentmods.dev/badge/rules/moasq/ios-dev-agent/mvvm-architecture.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 1,248 This file is loaded in full into every session.
When invoked 1,248 The same file — it is already loaded in full.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found 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.01248 $0.01248
Opus 5 $0.00624 $0.00624
Sonnet 5 $0.00250 $0.00250
Haiku 4.5 $0.00125 $0.00125

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

Security

Grade A, and why

mvvm-architecture 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.

.cursor/rules/mvvm-architecture.mdc · 164 lines

How it starts

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

MVVM Architecture Rules

Loadable Enum (Required for Async State)

Every app that performs async operations MUST include this enum as Shared/Loadable.swift:

// Shared/Loadable.swift
enum Loadable<T> {
    case notInitiated
    case loading
    case success(T)
    case failure(Error)

    var value: T? {
        if case .success(let v) = self { return v }
        return nil
    }

    var error: Error? {
        if case .failure(let e) = self { return e }
        return nil
    }

    var isLoading: Bool {
        if case .loading = self { return true }
        return false
    }
}

Rule: All async operations MUST use Loadable<T> for state tracking — never use var isLoading: Bool + var errorMessage: String?.

ViewModel Pattern (In-Memory Default)

Every ViewModel follows this exact pattern:

import SwiftUI

@Observable
@MainActor
class NotesListViewModel {
    var notes: [Note] = Note.sampleData
    var searchText = ""

    var filteredNotes: [Note] {
        if searchText.isEmpty { return notes }
        return notes.filter { $0.title.localizedCaseInsensitiveContains(searchText) }
    }

    func addNote(title: String) {
        let note = Note(title: title)
        notes.insert(note, at: 0)
    }

    func deleteNote(_ note: Note) {
        notes.removeAll { $0.id == note.id }
    }
}

ViewModel Pattern (Async Data)

When a ViewModel loads data asynchronously, use Loadable<T> and start loading in init():

import SwiftUI

@Observable
@MainActor
class NotesListViewModel {
    var notes: Loadable<[Note]> = .loading  // Start as .loading — init fires immediately
    var searchText = ""

    init() {
        Task { await loadNotes() }
    }

    var filteredNotes: [Note] {
        guard let allNotes = notes.value else { return [] }
        if searchText.isEmpty { return allNotes }
        return allNotes.filter { $0.title.localizedCaseInsensitiveContains(searchText) }
    }

    func loadNotes() async {
        notes = .loading
        do {
            notes = .success(try await fetchNotes())
        } catch {
            notes = .failure(error)
        }
    }
}

Read the full file on GitHub · 164 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 · 164 lines · 1,248 tokens per session scan A 21a5cb29c8aa

Subscribe to this mod's changes

mvvm-architecture is a cursor rule published in the GitHub repository moasq/ios-dev-agent (4 stars, last pushed 3mo ago), licensed MIT. It adds 1,248 tokens to every session, about $0.0062 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.