Skip to content

Commit 7363264

Browse files
committed
Fix compile error Xcode 14
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.
1 parent ba1bb55 commit 7363264

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

Sources/TUSKit/TUSClient.swift

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,18 @@ public final class TUSClient {
7676
private var uploads = [UUID: UploadMetadata]()
7777

7878
#if os(iOS)
79+
private var _backgroundClient: Any?
80+
7981
@available(iOS 13.0, *)
80-
private lazy var backgroundClient: TUSBackground = {
81-
return TUSBackground(api: api, files: files, chunkSize: chunkSize)
82-
}()
82+
/// Lazy properties are considered as stored properties in Swift 5.7, so they can no longer be marked as unavailable. Hence
83+
/// the computed property backed by storage var.
84+
private var backgroundClient: TUSBackground? {
85+
if _backgroundClient == nil {
86+
_backgroundClient = TUSBackground(api: api, files: files, chunkSize: chunkSize)
87+
}
88+
89+
return _backgroundClient as? TUSBackground
90+
}
8391
#endif
8492

8593
/// Initialize a TUSClient
@@ -289,7 +297,7 @@ public final class TUSClient {
289297
#if os(iOS)
290298
@available(iOS 13.0, *)
291299
public func scheduleBackgroundTasks() {
292-
backgroundClient.scheduleBackgroundTasks()
300+
backgroundClient?.scheduleBackgroundTasks()
293301
}
294302
#endif
295303

0 commit comments

Comments
 (0)