Skip to content

Commit

Permalink
Fix compile error Xcode 14
Browse files Browse the repository at this point in the history
Lazy properties are now considered stored properties, so they can no
longer be marked unavailable. This commit works around this by using a
computed var with backed storage.
  • Loading branch information
tursunovic committed Sep 12, 2022
1 parent ba1bb55 commit 7363264
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions Sources/TUSKit/TUSClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,18 @@ public final class TUSClient {
private var uploads = [UUID: UploadMetadata]()

#if os(iOS)
private var _backgroundClient: Any?

@available(iOS 13.0, *)
private lazy var backgroundClient: TUSBackground = {
return TUSBackground(api: api, files: files, chunkSize: chunkSize)
}()
/// Lazy properties are considered as stored properties in Swift 5.7, so they can no longer be marked as unavailable. Hence
/// the computed property backed by storage var.
private var backgroundClient: TUSBackground? {
if _backgroundClient == nil {
_backgroundClient = TUSBackground(api: api, files: files, chunkSize: chunkSize)
}

return _backgroundClient as? TUSBackground
}
#endif

/// Initialize a TUSClient
Expand Down Expand Up @@ -289,7 +297,7 @@ public final class TUSClient {
#if os(iOS)
@available(iOS 13.0, *)
public func scheduleBackgroundTasks() {
backgroundClient.scheduleBackgroundTasks()
backgroundClient?.scheduleBackgroundTasks()
}
#endif

Expand Down

0 comments on commit 7363264

Please sign in to comment.