2025 should be the year you stop using WCAG 2 colour contrast testing, and switch to APCA. This article is a few years old, and covers everything well. https://blog.datawrapper.de/color-contrast-check-data-vis-wcag-apca/
It's time for a more sophisticated color contrast check for data visualizations - Datawrapper Blog

The WCAG contrast requirements are flawed. Here's what a new approach could mean for data visualizations.

Datawrapper Blog
@marcedwards Very much agreed. Are you aware of any open-source Swift implementations?
@redalemeden Looks like we converted some JavaScript to Swift to do it.
@marcedwards I see! Might end up doing the same next time I need this to be running dynamically in-app.