From 0ab2c56fde98de1d037bfef1e62d97de87015b3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Javora?= Date: Thu, 1 Jun 2023 14:10:44 +0200 Subject: [PATCH] Added a workaround for a runtime crash when using `IDPreference`. --- .../Orbit/Support/Environment Keys/Identifier.swift | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Sources/Orbit/Support/Environment Keys/Identifier.swift b/Sources/Orbit/Support/Environment Keys/Identifier.swift index 39887981754..f9d13ce4cdd 100644 --- a/Sources/Orbit/Support/Environment Keys/Identifier.swift +++ b/Sources/Orbit/Support/Environment Keys/Identifier.swift @@ -41,4 +41,15 @@ public struct IDPreferenceKey: PreferenceKey { public struct IDPreference: Equatable { let id: AnyHashable let bounds: Anchor + + // `Anchor` is only conditionally `Equatable` since iOS 15. + // If synthesized, the compiler doesn't see any issues and this leads to a runtime crash on earlier iOS versions. + // That's why this is written here explicitly. + public static func == (lhs: IDPreference, rhs: IDPreference) -> Bool { + if #available(iOS 15, *) { + return lhs.id == rhs.id && lhs.bounds == rhs.bounds + } else { + return lhs.id == rhs.id + } + } }