Documentation Language: Swift

Class

MTLInMemoryStrategy

In-memory generation strategy for testing and programmatic access.

actor MTLInMemoryStrategy

Overview

This strategy accumulates generated text in memory rather than writing to files, making it ideal for unit tests, previews, and scenarios where the generated text needs to be processed programmatically.

Overview

Features:

Example Usage

let strategy = MTLInMemoryStrategy()

// Generate multiple "files"
let writer1 = try await strategy.createWriter(
    url: "file1.txt",
    mode: .create,
    charset: "UTF-8",
    indentation: MTLIndentation()
)
await writer1.writeLine("Content 1")
try await strategy.finalizeWriter(writer1)

let writer2 = try await strategy.createWriter(
    url: "file2.txt",
    mode: .create,
    charset: "UTF-8",
    indentation: MTLIndentation()
)
await writer2.writeLine("Content 2")
try await strategy.finalizeWriter(writer2)

// Retrieve all generated content
let files = await strategy.getGeneratedFiles()
print(files["file1.txt"])  // "Content 1\n"
print(files["file2.txt"])  // "Content 2\n"

Topics

Initializers

?
init()

Creates a new in-memory generation strategy.

Instance Methods

F
clear()

Clears all generated files from memory.

F
createWriter(url:mode:charset:indentation:)

Creates a new writer for the specified target.

F
finalizeWriter(_:)

Finalizes and commits the writer’s content to its target.

F
getGeneratedFiles()

Returns all generated files and their contents.

Default Implementations

Relationships

Conforms To