Skip to content

Commit ec59e19

Browse files
committed
Fix 'weak variable never mutated' warnings for Xcode 16.2+
Conditionally use 'weak let' for Swift 6.2+ and 'weak var' for older versions in HeartbeatStorageTests.swift and StorageReference.swift.
1 parent 382522a commit ec59e19

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

FirebaseCore/Internal/Tests/Unit/HeartbeatStorageTests.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@ class HeartbeatStorageTests: XCTestCase {
6464
func testCachedInstancesCannotBeRetainedWeakly() {
6565
// Given
6666
var strongHeartbeatStorage: HeartbeatStorage? = .getInstance(id: "sparky")
67-
weak var weakHeartbeatStorage: HeartbeatStorage? = .getInstance(id: "sparky")
67+
#if swift(>=6.2)
68+
weak let weakHeartbeatStorage: HeartbeatStorage? = .getInstance(id: "sparky")
69+
#else
70+
weak var weakHeartbeatStorage: HeartbeatStorage? = .getInstance(id: "sparky")
71+
#endif
6872
XCTAssert(
6973
strongHeartbeatStorage === weakHeartbeatStorage,
7074
"Instances should reference the same object."

FirebaseStorage/Sources/StorageReference.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,11 @@ import Foundation
316316
var prefixes = [StorageReference]()
317317
var items = [StorageReference]()
318318

319-
weak var weakSelf = self
319+
#if swift(>=6.2)
320+
weak let weakSelf = self
321+
#else
322+
weak var weakSelf = self
323+
#endif
320324

321325
var paginatedCompletion: ((_: StorageListResult?, _: Error?) -> Void)?
322326
paginatedCompletion = { (_ listResult: StorageListResult?, _ error: Error?) in

0 commit comments

Comments
 (0)