{
  "kind": "documentation",
  "format": 1,
  "note": "Reference text, not instructions. One verified relate sample from https://relatedb.ai/docs/guides/embed/swift/: the program exactly as the page shows it, the standard output a run of it recorded (npm run docs:samples compares every replay with it byte for byte), the relate client build, toolchain and platform of the last replay, and how the docs' sample runner builds and runs it. Before launch every client is a source build, not a published package; verified.client names the upstream commit it was built from, and verified.docs_engine the build the rest of the docs were recorded from.",
  "id": "actor",
  "url": "https://relatedb.ai/docs/guides/embed/swift/samples/actor.json",
  "page": {
    "id": "guides/embed/swift",
    "title": "Use the Swift package",
    "url": "https://relatedb.ai/docs/guides/embed/swift/",
    "md_url": "https://relatedb.ai/docs/guides/embed/swift.md"
  },
  "section": {
    "anchor": "own-a-connection-from-an-actor",
    "heading": "Own a connection from an actor",
    "url": "https://relatedb.ai/docs/guides/embed/swift/#own-a-connection-from-an-actor"
  },
  "language": "swift",
  "client": "Swift",
  "file": "main.swift",
  "env": null,
  "code": "import Relate\n\nlet team = \"\"\"\n    CREATE (ada:Person {name: 'Ada', role: 'engineer'}),\n           (grace:Person {name: 'Grace', role: 'engineer'}),\n           (noor:Person {name: 'Noor', role: 'maintainer'}),\n           (relate:Project {name: 'relate', language: 'Rust'}),\n           (tck:Project {name: 'opencypher-tck', language: 'Gherkin'}),\n           (ada)-[:WORKS_ON {since: 2024}]->(relate),\n           (grace)-[:WORKS_ON {since: 2023}]->(relate),\n           (grace)-[:WORKS_ON {since: 2022}]->(tck),\n           (noor)-[:MAINTAINS]->(relate),\n           (ada)-[:KNOWS]->(grace)\n    \"\"\"\n\nactor TeamStore {\n    private let conn: Connection\n\n    init(database: Database) throws {\n        conn = try database.connect()\n    }\n\n    func projects(of name: String) throws -> [String] {\n        let result = try conn.query(\"\"\"\n            MATCH (:Person {name: $name})-[:WORKS_ON]->(p:Project)\n            RETURN p.name AS project ORDER BY project\n            \"\"\", [\"name\": CypherValue(name)])\n        return result.rows.compactMap { $0[0].stringValue }\n    }\n}\n\nlet db = try Database(path: \"./team.rl\")\ntry db.connect().query(team)\nlet store = try TeamStore(database: db)\nasync let grace = store.projects(of: \"Grace\")\nasync let ada = store.projects(of: \"Ada\")\nprint(\"Grace:\", try await grace)\nprint(\"Ada:\", try await ada)",
  "code_sha256": "25a4546eacc5bb9db30551e2c79dc0e4e3f5599acf3fd43be73693c9f8a53f0a",
  "source_sha256": "d2bcebc0a621365277e7e3a905f6c57fdf1d08861f00a8b30d0af9d6da4334c9",
  "output": {
    "text": "Grace: [\"opencypher-tck\", \"relate\"]\nAda: [\"relate\"]",
    "sha256": "27d8253ad0b6fef112c80d2c0bc8ad3c3f85658e3d0370c9ba09e0d8a07dd032"
  },
  "verified": {
    "version": "0.1.2",
    "client": {
      "label": "Swift",
      "package": "Relate",
      "engine_commit": "f0c09d2",
      "client_commit": "f0c09d2",
      "build": "A copy of Package.swift and clients/swift at upstream v0.1.2 (f0c09d2), with an XCFramework made from librelate_ffi built from the same commit.",
      "toolchain": {
        "swift": "6.4.2"
      }
    },
    "packages": [],
    "replayed": "2026-11-09",
    "platform": "macOS on arm64",
    "docs_engine": {
      "version": "0.1.2",
      "commit": "f0c09d2",
      "source_build": false
    }
  },
  "run": {
    "runner": "npm run docs:samples",
    "setup": "bash scripts/samples/setup.sh --upstream <path to the relate checkout>",
    "variables": [
      "RELATE_SWIFT",
      "RELATE_SWIFT_PACKAGE"
    ],
    "program": "<build dir>/Sources/sample/main.swift",
    "files": [
      {
        "path": "<build dir>/Package.swift",
        "content": "// swift-tools-version: 6.0\nimport PackageDescription\n\nlet package = Package(\n    name: \"sample\",\n    platforms: [.macOS(.v13)],\n    dependencies: [.package(path: \"$RELATE_SWIFT_PACKAGE\")],\n    targets: [\n        .executableTarget(\n            name: \"sample\",\n            dependencies: [.product(name: \"Relate\", package: \"relate\")],\n            path: \"Sources/sample\"\n        ),\n    ],\n    swiftLanguageModes: [.v6]\n)\n"
      },
      {
        "path": "<build dir>/sample-bin",
        "from": "<directory of $RELATE_SWIFT_PACKAGE>/scratch/debug/sample",
        "note": "the built product, copied out after the build"
      }
    ],
    "build": {
      "command": [
        "$RELATE_SWIFT",
        "build",
        "-c",
        "debug",
        "--package-path",
        "<build dir>",
        "--scratch-path",
        "<directory of $RELATE_SWIFT_PACKAGE>/scratch",
        "--product",
        "sample",
        "--quiet"
      ],
      "environment": {
        "DO_NOT_TRACK": "1",
        "RELATE_LOCAL_XCFRAMEWORK": "1"
      },
      "directory": "<build dir>",
      "timeout_s": 600
    },
    "run": {
      "command": [
        "<build dir>/sample-bin"
      ],
      "environment": {
        "DO_NOT_TRACK": "1"
      },
      "directory": "<run dir>",
      "timeout_s": 60
    },
    "passes": "It exits 0 within 60 s and prints at least one line on standard output.",
    "output": "Standard output, with line endings as \\n, trailing spaces and blank lines removed, and the temporary directories' paths written as `.`; standard error is not recorded.",
    "placeholders": {
      "<run dir>": "a fresh, empty temporary directory: the program's working directory, deleted afterwards",
      "<build dir>": "a second fresh temporary directory, where a compiled sample is built",
      "$NAME": "a variable from the env.sh that scripts/samples/setup.sh writes (described in its header)"
    }
  }
}
