AlQamar: An iPhone Cycle Tracker That Says How Sure It Is
AlQamar is a native iPhone period and cycle tracker, written in SwiftUI. It measures cycles from whole periods instead of single taps, says how sure it is, and keeps all of its data on the phone.
I built it as a gift for my wife. It is not on the App Store. I install it from Xcode under a free personal team, and a small script, deploy.sh, rebuilds and reinstalls it over Wi-Fi, because a free install expires after seven days.
Version 1.3.0 is about 7,500 lines of Swift, an app plus a widget extension. The README puts it plainly: AlQamar is not a medical device or a contraceptive method, and predictions are estimates.
What it does
- Today: a cycle wheel with a moon that is new at the period and full at ovulation, and one button to log the day.
- Calendar and Insights: periods, fertile and peak days, trends in Swift Charts, symptom patterns and the next three periods.
- Logging: symptoms and mood as one-tap chips, LH tests, basal temperature and notes.
- Widgets, a Live Activity during a period, local reminders, a PDF report for a doctor, and English, Arabic and Spanish.
Periods, not taps
People log a period one day at a time, so one period becomes several records. Measure cycles between records and the cycle comes out far too short. So the engine, CycleDataManager, first merges day logs into episodes. A log within two days of the previous one joins it, so one forgotten day does not split a period.
- Cycle length runs from the first day of one episode to the first day of the next. Gaps outside 15 to 45 days are left out, and Insights says so instead of hiding them.
- The average covers the last 12 cycles, weighted toward recent ones. Outliers are dropped by median absolute deviation, but the cut-off is never tighter than five days: a real long cycle is data, and dropping it pulls every later prediction early.
- Predictions start from the first day of the latest episode, not the last day logged.
Ovulation from the stable half
The code treats the luteal phase, from ovulation to the next period, as the stable half of the cycle, held at 14 days. So it counts backwards: ovulation is 14 days before the predicted next period. The fertile window is the five days before ovulation plus the day itself, and the two days before ovulation are marked as peak. For past cycles it counts back from the day the next period really started.
An observation beats the calendar. A positive LH test puts ovulation on the next day. Without one, basal temperature can confirm it with the three-over-six rule: three days in a row above the highest of the previous six readings, one of them at least 0.2 °C higher. The next period is then predicted one luteal phase later, measured from the user's own past observations when there are any (9 to 17 days). The wheel, the moon, the calendar and the widget all follow the same pinned day.
Confidence that can go down
The confidence score multiplies four things: the spread of recent cycles (seven days of spread scores zero), how many cycles there are (full credit at six), how late the period is (it fades to zero over two weeks), and whether the cycle is an estimate (that halves it).
- Predictions carry a ± spread once there are three cycles to measure it from.
- Regularity shows a dash until two cycles are measured, rather than a 100% from one sample.
- The average cycle is labelled "est." until a full cycle has been measured.
- Overdue stays overdue. Only after a whole extra cycle with nothing logged does the screen switch to "Estimated cycle" and ask for the next period.
On the phone, and only there
No account, no server, no analytics. There is no network code at all and no third-party SDK. Data is JSON in UserDefaults, inside an App Group shared with the widget. Reminders are local notifications, and the app updates the Live Activity itself, without push. There is no iCloud sync either, by choice. Nothing leaves the phone unless the user shares a backup or the report.
- A cover window hides the screen from the app switcher, and an optional Face ID lock covers open sheets too.
- Widgets redact when the phone is locked, the Live Activity has an off switch, and discreet mode gives every reminder a generic title and body.
- A backup is a JSON file written with complete file protection and deleted as soon as the share sheet closes.
Tests
69 XCTest tests in three suites: 60 for the engine, 7 for the notification scheduler against a spy, and 2 for backup round trips. The engine runs on its own UserDefaults suite with a frozen clock. Several of them pin a bug that was found and fixed:
- Days were stored at local midnight, which reads as the day before in any time zone further west. They are now stored at noon, which survives eleven hours of travel either way.
- The scheduler wiped all reminders before it knew whether notifications were allowed, so every cold launch deleted them and added nothing back. It now checks first.
xcodegen generate xcodebuild -project AlQamar.xcodeproj -scheme AlQamar \ -destination 'platform=iOS Simulator,name=iPhone 17' test
XcodeGen, a third-party open-source tool, generates the Xcode project from project.yml.
What I'd do next
- Confidence from one cycle. With one measured cycle there is no spread yet, so that term counts as perfect and the score starts at 63%. Regularity refuses to guess from one cycle; confidence should too.
- Encrypt the backup itself. File protection only applies on the phone. Once shared, the JSON is plain text wherever it lands.
- Use the measured luteal phase everywhere. It is used after an observed ovulation, but calendar estimates and past cycles still count back a fixed 14 days.