diff --git a/Sources/ApexyLoader/ContentLoader.swift b/Sources/ApexyLoader/ContentLoader.swift index 921ad98..cac4938 100644 --- a/Sources/ApexyLoader/ContentLoader.swift +++ b/Sources/ApexyLoader/ContentLoader.swift @@ -38,14 +38,32 @@ open class ContentLoader: ObservableLoader { } } + // Can not use `@available` with lazy properties in Xcode 14. This is a workaround. + // https://stackoverflow.com/a/55534141/7453375 + private var storedStateSubject: Any? @available(iOS 13.0, macOS 10.15, watchOS 6.0, tvOS 13.0, *) - private lazy var stateSubject = CurrentValueSubject, Never>(.initial) + private var stateSubject: CurrentValueSubject, Never> { + if let subject = storedStateSubject as? CurrentValueSubject, Never> { + return subject + } + let subject = CurrentValueSubject, Never>(.initial) + storedStateSubject = subject + return subject + } /// Content loading status. The default value is `.initial`. /// /// - Remark: To change state use `update(_:)`. + private var storedStatePublisher: Any? @available(iOS 13.0, macOS 10.15, watchOS 6.0, tvOS 13.0, *) - public lazy var statePublisher: AnyPublisher, Never> = stateSubject.eraseToAnyPublisher() + public var statePublisher: AnyPublisher, Never> { + if let publisher = storedStatePublisher as? AnyPublisher, Never> { + return publisher + } + let publisher = stateSubject.eraseToAnyPublisher() + storedStatePublisher = publisher + return publisher + } public init() {}