Structure
MTLBlock
Represents a block of MTL statements.
struct MTLBlock
Overview
Blocks group statements together for execution as a unit, supporting both inlined blocks (no indentation) and standard blocks (with indentation). They form the body of templates, loops, conditionals, and other control structures.
Overview
MTL blocks serve multiple purposes:
-
Template bodies: The main content of a template
-
Control flow bodies: Content within for loops, if statements, etc.
-
File blocks: Content to be written to a specific file
-
Macro bodies: Reusable content patterns
Example Usage
// Simple text block
let textBlock = MTLBlock(statements: [
MTLTextStatement(value: "public class "),
MTLExpressionStatement(expression: nameExpr),
MTLTextStatement(value: " {"),
MTLNewLineStatement()
])
// Inlined block (no indentation changes)
let inlinedBlock = MTLBlock(
statements: [
MTLTextStatement(value: "inline content")
],
inlined: true
)
Topics
Operators
Compares two MTL blocks for equality.
Initializers
Creates a new MTL block.
Instance Properties
Whether this block is inlined (no indentation changes).
The statements in this block.
Instance Methods
Executes all statements in this block within the given context.
Hashes the essential components of the block into the given hasher.