How dreymonde/nicenotifications works
Project Type and Purpose
• This is an open-source Swift Package (library) named NiceNotifications that reimagines local notifications on Apple platforms.
• It provides a declarative API for scheduling, grouping, permission‐handling, and “timelines” of local notifications.
• Consumers integrate this package into their iOS, watchOS, tvOS, or macOS app via Swift Package Manager.
File Structure Analysis
Top-level artifacts:
• Package.swift / Package.resolved – SwiftPM manifest and lock file.
• Sources/NiceNotifications – the library’s implementation.
– NiceNotifications.swift: main façade (LocalNotifications).
– NotificationPermissionView.swift: UI component for group-level permission.
• Tests/NiceNotificationsTests – unit tests for the library.
• Xcode workspace files under .swiftpm/xcode – project-level configuration.
README Insights
• Describes core concepts: scheduling APIs, permission strategies (system vs group-level), “Notification Timelines,” and advanced guides.
• Mentions dependencies (Apple’s UserNotifications framework and an external DateBuilder library).
Main Components
a. Consumer App (host app)
b. NiceNotifications Library
• Facade / API Layer: LocalNotifications static methods
• Trigger Definition: DateBuilder types (e.g., EveryDay, NextWeek)
• Timeline Builder: NotificationsTimeline and LocalNotificationsGroup protocol
• Permission Layer:
– SystemLevel (UNUserNotificationCenter)
– GroupLevel (NotificationsPermissionView + in-code strategies)
c. Apple’s UserNotifications Framework (UNUserNotificationCenter)
d. (Optional) DateBuilder External Module
e. Storage: persisting group-level permissions (e.g., UserDefaults)
Relationships & Data Flow
1. Consumer App calls LocalNotifications.schedule(...) or reschedule(group:…).
2. The DateBuilder trigger objects build next fire dates.
3. NotificationsTimeline prepares a sequence of UNNotificationRequests.
4. Permission strategies execute:
– Group-level check (UI or bypass)
– System-level check (ask or validate via UNUserNotificationCenter.getNotificationSettings)
5. On approval, library calls UNUserNotificationCenter.add(request).
6. For groups, LocalNotificationsGroup.getTimeline may be invoked periodically.
7. UI component (NotificationPermissionView) reads/writes group permission state and shows toggles.
Architectural Patterns & Principles
• Facade pattern: LocalNotifications simplifies complex interactions.
• Builder pattern: DateBuilder helps declare triggers (Tomorrow().at(...)).
• Strategy pattern: PermissionStrategy composes group vs system strategies.
• Protocol-oriented design: LocalNotificationsGroup, PermissionAsker.
• Separation of concerns: UI (permission view) separated from core scheduling logic.
Essential Elements
• Clear labels: module names and key classes/protocols.
• Notes on strategies: show strategy selection branch between group vs system.