From c1d64a8027ac87cfc9c3ed675870c47cc971fca1 Mon Sep 17 00:00:00 2001 From: Riley Testut Date: Wed, 17 Aug 2022 15:22:43 -0500 Subject: [PATCH] =?UTF-8?q?Fixes=20=E2=80=9Cstored=20properties=20cannot?= =?UTF-8?q?=20be=20marked=20@available=E2=80=9D=20compiler=20error?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- AltStore/AppDelegate.swift | 22 ++++++++++++++++++--- AltStore/Managing Apps/AppManager.swift | 26 ++++++++++++++++++++----- 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/AltStore/AppDelegate.swift b/AltStore/AppDelegate.swift index 49be4e2a..dbbf160f 100644 --- a/AltStore/AppDelegate.swift +++ b/AltStore/AppDelegate.swift @@ -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. diff --git a/AltStore/Managing Apps/AppManager.swift b/AltStore/Managing Apps/AppManager.swift index f9ddba2d..a440824a 100644 --- a/AltStore/Managing Apps/AppManager.swift +++ b/AltStore/Managing Apps/AppManager.swift @@ -46,9 +46,6 @@ class AppManager { static let shared = AppManager() - @available(iOS 13, *) - private(set) lazy var publisher: AppManagerPublisher = AppManagerPublisher() - private(set) var updatePatronsResult: Result? private let operationQueue = OperationQueue() @@ -67,8 +64,27 @@ class AppManager } } - @available(iOS 13.0, *) - private lazy var cancellables = Set() + @available(iOS 13, *) + private(set) var publisher: AppManagerPublisher { + get { _publisher as! AppManagerPublisher } + set { _publisher = newValue } + } + + @available(iOS 13, *) + private(set) var cancellables: Set { + get { _cancellables as! Set } + set { _cancellables = newValue } + } + + private lazy var _publisher: Any = { + guard #available(iOS 13, *) else { fatalError() } + return AppManagerPublisher() + }() + + private lazy var _cancellables: Any = { + guard #available(iOS 13, *) else { fatalError() } + return Set() + }() private init() {