Spezi modules can enforce specific requirements on the Standard instance used within an application via a constraint mechanism. This ensures that any module integrated into a project has access to the necessary capabilities or data provided by the Standard actor.
To implement constraints, a module defines a protocol that inherits from the Standard protocol:
protocol ExampleConstraint: Standard {
// ...
}
As an application developer, you must ensure the Standard instance provided in your Configuration satisfies these constraints. You can do this by either:
- Defining a custom Standard: Create an actor that conforms to both
Standard and the required constraint protocol. - Extending an existing Standard: Use Swift extensions to make a predefined
Standard conform to the required protocol.
Once configured, you can access the current Standard instance within a Module using the @StandardActor property wrapper, or within SwiftUI views using the @Environment property wrapper (provided the view conforms to EnvironmentAccessible).
protocol ExampleConstraint: Standard {
// ...
}