{"id":50115172,"url":"https://github.com/bootuz/swiftfsrs","last_synced_at":"2026-05-23T14:05:06.794Z","repository":{"id":324233307,"uuid":"1096489494","full_name":"bootuz/SwiftFSRS","owner":"bootuz","description":"A Swift implementation of the Free Spaced Repetition Scheduler (FSRS-6) algorithm.","archived":false,"fork":false,"pushed_at":"2025-11-14T15:47:23.000Z","size":93,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-11-14T16:10:41.632Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bootuz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-11-14T13:59:12.000Z","updated_at":"2025-11-14T15:47:26.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/bootuz/SwiftFSRS","commit_stats":null,"previous_names":["bootuz/swiftfsrs"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/bootuz/SwiftFSRS","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bootuz%2FSwiftFSRS","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bootuz%2FSwiftFSRS/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bootuz%2FSwiftFSRS/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bootuz%2FSwiftFSRS/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bootuz","download_url":"https://codeload.github.com/bootuz/SwiftFSRS/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bootuz%2FSwiftFSRS/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33398432,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-23T04:15:53.637Z","status":"ssl_error","status_checked_at":"2026-05-23T04:15:53.242Z","response_time":53,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-05-23T14:05:05.001Z","updated_at":"2026-05-23T14:05:06.784Z","avatar_url":"https://github.com/bootuz.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Swift FSRS\n\n[![Build](https://github.com/bootuz/SwiftFSRS/actions/workflows/swift.yml/badge.svg)](https://github.com/bootuz/SwiftFSRS/actions/workflows/swift.yml)\n![Swift 5.9+](https://img.shields.io/badge/Swift-5.9%2B-orange.svg)\n![Platform](https://img.shields.io/badge/platform-iOS%20%7C%20macOS%20%7C%20watchOS%20%7C%20tvOS-lightgrey.svg)\n[![License](https://img.shields.io/github/license/bootuz/SwiftFSRS.svg)](https://github.com/bootuz/SwiftFSRS/blob/main/LICENSE)\n[![Swift Package Manager](https://img.shields.io/badge/Swift_Package_Manager-compatible-orange?style=flat-square)](https://swift.org/package-manager/)\n\nA Swift implementation of the Free Spaced Repetition Scheduler (FSRS-6) algorithm.\n\n## Overview\n\nSwift FSRS is a native Swift package that implements the FSRS-6 spaced repetition scheduler algorithm for flashcard applications. It provides a clean, type-safe API following Swift best practices.\n\n## Features\n\n- ✅ Complete FSRS-6 algorithm implementation\n- ✅ Protocol-oriented design - works with your own card types\n- ✅ Concurrency support\n- ✅ Card scheduling with learning steps support (BasicScheduler)\n- ✅ Long-term scheduling without learning steps (LongTermScheduler)\n- ✅ Reschedule functionality for replaying review history\n- ✅ Rollback capability to undo reviews\n- ✅ Forget functionality to reset cards\n- ✅ Retrievability calculation (formatted and numeric)\n- ✅ Customizable strategies (seed, learning steps)\n- ✅ Parameter migration support (FSRS-4/5/6 compatibility)\n- ✅ Logging support with FSRSLogger protocol\n\n## Installation\n\n### Swift Package Manager\n\nAdd the following to your `Package.swift`:\n\n```swift\ndependencies: [\n    .package(url: \"https://github.com/yourusername/swift-fsrs.git\", from: \"1.0.0\")\n]\n```\n\nOr add it via Xcode:\n1. File → Add Packages...\n2. Enter the repository URL\n3. Select version and add to your target\n\n## Usage\n\n### Implementing FSRSCard Protocol\n\nFirst, create a card type that conforms to the `FSRSCard` protocol:\n\n```swift\nimport FSRS\n\nstruct Flashcard: FSRSCard {\n    // Your custom properties\n    let id: UUID\n    var question: String\n    var answer: String\n    \n    // FSRS required properties\n    var due: Date\n    var state: State\n    var lastReview: Date?\n    var stability: Double\n    var difficulty: Double\n    var scheduledDays: Int\n    var learningSteps: Int\n    var reps: Int\n    var lapses: Int\n    \n    init(question: String, answer: String) {\n        self.id = UUID()\n        self.question = question\n        self.answer = answer\n        \n        // Initialize FSRS properties for new card\n        self.due = Date()\n        self.state = .new\n        self.lastReview = nil\n        self.stability = 0\n        self.difficulty = 0\n        self.scheduledDays = 0\n        self.learningSteps = 0\n        self.reps = 0\n        self.lapses = 0\n    }\n}\n```\n\n### Basic Example\n\n```swift\nimport FSRS\n\n// Create FSRS instance with default parameters (specify your card type)\nlet f = fsrs\u003cFlashcard\u003e()\n\n// Create a new card\nlet card = Flashcard(question: \"What is the capital of France?\", answer: \"Paris\")\nlet now = Date()\n\n// Preview all rating scenarios\nlet recordLog = try f.repeat(card: card, now: now)\n\n// Get card for a specific rating\nlet goodCard = recordLog[.good]!.card\nlet goodLog = recordLog[.good]!.log\n\n// Review with a specific rating\nlet result = try f.next(card: card, now: now, rating: .good)\nlet nextCard = result.card\n\n// Get retrievability as formatted string\nlet retrievability = f.getRetrievability(card: card, now: now)\nprint(retrievability) // \"90.00%\"\n\n// Get retrievability as numeric value\nlet retrievabilityValue = f.getRetrievabilityValue(card: card, now: now)\nprint(retrievabilityValue) // 0.9\n```\n\n### Custom Parameters\n\n```swift\nlet config = FSRSConfiguration(\n    requestRetention: 0.9,\n    maximumInterval: 36500,\n    enableFuzz: true,\n    enableShortTerm: true\n)\nlet f = FSRS\u003cFlashcard\u003e(configuration: config)\n```\n\n### Reschedule with History\n\nReplay a card's review history to recalculate its state:\n\n```swift\nlet now = Date()\nlet reviews: [FSRSHistory] = [\n    FSRSHistory(rating: .good, review: now),\n    FSRSHistory(rating: .good, review: now.addingTimeInterval(86400)),\n    FSRSHistory(rating: .again, review: now.addingTimeInterval(172800))\n]\n\nlet options = RescheduleOptions\u003cFlashcard\u003e(\n    updateMemoryState: true,\n    now: Date()\n)\n\nlet result = try f.reschedule(\n    currentCard: card,\n    reviews: reviews,\n    options: options\n)\n\nprint(result.collections.count) // Number of replayed reviews\nif let rescheduleItem = result.rescheduleItem {\n    let updatedCard = rescheduleItem.card\n}\n```\n\n### Rollback\n\nUndo a review and restore the card to its previous state:\n\n```swift\n// After reviewing a card, you get a RecordLogItem\nlet result = try f.next(card: card, now: Date(), rating: .good)\nlet currentCard = result.card\nlet reviewLog = result.log\n\n// Rollback to previous state\nlet previousCard = try f.rollback(card: currentCard, log: reviewLog)\n```\n\n### Forget Card\n\nReset a card back to the new state:\n\n```swift\nlet forgottenResult = f.forget(card: card, now: Date(), resetCount: false)\nlet newCard = forgottenResult.card\n// Card is now in .new state with reset stability and difficulty\n```\n\n## Architecture\n\nThe package is organized into the following modules:\n\n### Core Components\n- **Models**: Core data structures (ReviewLog, Parameters, Enums, ValueObjects)\n- **Protocols**: Protocol definitions (FSRSCard, AlgorithmProtocols, SchedulerProtocol)\n- **Core**: Main algorithm (FSRSAlgorithm, FSRS, Factory) and parameter management\n- **Schedulers**: Scheduling logic (BasicScheduler, LongTermScheduler, BaseScheduler)\n- **Calculators**: Separate calculators for stability, difficulty, and intervals\n\n### Features\n- **Strategies**: Extensible strategy system (seed, learning steps)\n- **Features**: Advanced features (Reschedule, RetrievabilityService, CardStateService)\n- **Utilities**: Helper functions (DateHelpers, MathHelpers, Alea PRNG, FSRSLogger)\n\n### Design Patterns\n- **Protocol-Oriented**: Use `FSRSCard` protocol to work with your own card types\n- **Generic Types**: FSRS is generic over any card type conforming to FSRSCard\n- **Value Objects**: Type-safe wrappers for domain values (Stability, Difficulty, etc.)\n- **Service Layer**: Separate services for retrievability, card state, and rescheduling\n\n\n## Swift Version\n\nRequires Swift 5.9+\n\n## Testing\n\n- **State Transition Tests**: Verify correct state machine behavior for all card states\n- **Parameter Tests**: Test parameter validation, migration, and clipping\n- **Integration Tests**: End-to-end testing of complete workflows\n- **API Tests**: Verify all public API methods work correctly\n\nHow to run tests:\n\n```bash\nswift test\n```\n\nRun specific test suites:\n\n```bash\nswift test --filter StateTransitionTests\nswift test --filter IntegrationTests\n```\n\n## Status\n\nThis is a complete, production-ready implementation of FSRS-6 for Swift. All core functionality has been implemented and tested:\n\n- ✅ Complete FSRS-6 algorithm with all formulas\n- ✅ Short-term and long-term scheduling modes\n- ✅ Protocol-based generic design for flexibility\n- ✅ Comprehensive test suite with 125+ tests\n\n## Contributing\n\nContributions are welcome! Please ensure:\n- All changes are made through forked repository\n- Code follows Swift style guidelines\n- Tests are added for new features\n- All tests pass: `swift test`\n- Documentation is updated\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbootuz%2Fswiftfsrs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbootuz%2Fswiftfsrs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbootuz%2Fswiftfsrs/lists"}