Fixes “stored properties cannot be marked @available” compiler error

Xcode 13 and earlier allowed us to mark lazy stored properties with @available, but it turns out this was never actually supported. Xcode 14 now throws a compiler error, so we work around it by converting lazy @available properties into computed properties, backed by typed-erased lazy ivars.
This commit is contained in:
Riley Testut
2022-08-17 15:22:43 -05:00
parent 1bc2aa9d38
commit c1d64a8027
2 changed files with 40 additions and 8 deletions

View File

@@ -34,11 +34,27 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
@available(iOS 14, *)
private lazy var intentHandler = IntentHandler()
private var intentHandler: IntentHandler {
get { _intentHandler as! IntentHandler }
set { _intentHandler = newValue }
}
@available(iOS 14, *)
private lazy var viewAppIntentHandler = ViewAppIntentHandler()
private var viewAppIntentHandler: ViewAppIntentHandler {
get { _viewAppIntentHandler as! ViewAppIntentHandler }
set { _viewAppIntentHandler = newValue }
}
private lazy var _intentHandler: Any = {
guard #available(iOS 14, *) else { fatalError() }
return IntentHandler()
}()
private lazy var _viewAppIntentHandler: Any = {
guard #available(iOS 14, *) else { fatalError() }
return ViewAppIntentHandler()
}()
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool
{
// Register default settings before doing anything else.