Skip to main content

Challenges

Challenges are the core of PrismGamification. Define them as a Swift enum conforming to PrismChallenge, and the manager handles persistence, progress tracking, and events.

The PrismChallenge Protocol

Protocol Definition

Challenge Types

Complete Example

Registration

Register all cases of your challenge enum. Idempotent — safe to call on every app launch:
Register Challenges

Tracking Progress

Counter Challenges

Increment
Progress auto-completes when currentValue >= goal. Values clamp to goal — never overshoot.
Calling increment on a milestone challenge throws PrismGamificationError.invalidOperation. Use complete instead.

Milestone Challenges

Complete
Calling complete or increment on an already-completed challenge throws PrismGamificationError.challengeAlreadyCompleted.

Querying Progress

Queries

PrismChallengeSnapshot

All queries return PrismChallengeSnapshot — a Sendable value type:

Resetting

Reset

Events

Subscribe to challenge events via AsyncStream:
Event Stream

Error Handling

All errors are PrismGamificationError — equatable and localized.