Skip to content

Commit 999881c

Browse files
authored
Make APIs returning monitoring tasks discardable (#5246)
1 parent 795a66d commit 999881c

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

FirebaseStorageSwift/Sources/SwiftAPIExtension.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public extension StorageReference {
6161
/// an `Error`.
6262
///
6363
/// - Returns: A StorageDownloadTask that can be used to monitor or manage the download.
64+
@discardableResult
6465
func getData(maxSize: Int64, completion: @escaping (Result<Data, Error>) -> Void)
6566
-> StorageDownloadTask {
6667
return getData(maxSize: maxSize, completion: getResultCallback(completion: completion))
@@ -147,6 +148,7 @@ public extension StorageReference {
147148
///
148149
/// - Returns: An instance of `StorageUploadTask`, which can be used to monitor or manage
149150
/// the upload.
151+
@discardableResult
150152
func putData(_ uploadData: Data,
151153
metadata: StorageMetadata? = nil,
152154
completion: @escaping (Result<StorageMetadata, Error>) -> Void)
@@ -167,6 +169,7 @@ public extension StorageReference {
167169
///
168170
/// - Returns: An instance of `StorageUploadTask`, which can be used to monitor or manage
169171
/// the upload.
172+
@discardableResult
170173
func putFile(from: URL,
171174
metadata: StorageMetadata? = nil,
172175
completion: @escaping (Result<StorageMetadata, Error>) -> Void)
@@ -184,7 +187,7 @@ public extension StorageReference {
184187
/// object metadata or an `Error`.
185188
func updateMetadata(_ metadata: StorageMetadata,
186189
completion: @escaping (Result<StorageMetadata, Error>) -> Void) {
187-
return updateMetadata(metadata, completion: getResultCallback(completion: completion))
190+
updateMetadata(metadata, completion: getResultCallback(completion: completion))
188191
}
189192

190193
/// Asynchronously downloads the object at the current path to a specified system filepath.
@@ -196,6 +199,7 @@ public extension StorageReference {
196199
/// path of the downloaded file or an `Error`.
197200
///
198201
/// - Returns: A `StorageDownloadTask` that can be used to monitor or manage the download.
202+
@discardableResult
199203
func write(toFile: URL, completion: @escaping (Result<URL, Error>)
200204
-> Void) -> StorageDownloadTask {
201205
return write(toFile: toFile, completion: getResultCallback(completion: completion))

FirebaseStorageSwift/Tests/Integration/StorageIntegration.swift

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ class StorageIntegration: XCTestCase {
4949

5050
for largeFile in largeFiles {
5151
let ref = storage.reference().child(largeFile)
52-
_ = ref.putData(data) { result in
52+
ref.putData(data) { result in
5353
self.assertResultSuccess(result)
5454
setupExpectation.fulfill()
5555
}
5656
}
5757
for emptyFile in emptyFiles {
5858
let ref = storage.reference().child(emptyFile)
59-
_ = ref.putData(data) { result in
59+
ref.putData(data) { result in
6060
self.assertResultSuccess(result)
6161
setupExpectation.fulfill()
6262
}
@@ -114,7 +114,7 @@ class StorageIntegration: XCTestCase {
114114
let expectation = self.expectation(description: #function)
115115
let ref = storage.reference(withPath: "ios/public/fileToDelete")
116116
let data = try XCTUnwrap("Hello Swift World".data(using: .utf8), "Data construction failed")
117-
_ = ref.putData(data) { result in
117+
ref.putData(data) { result in
118118
self.assertResultSuccess(result)
119119
ref.delete() { error in
120120
XCTAssertNil(error, "Error should be nil")
@@ -128,7 +128,7 @@ class StorageIntegration: XCTestCase {
128128
let expectation = self.expectation(description: #function)
129129
let ref = storage.reference(withPath: "ios/public/fileToDelete")
130130
let data = try XCTUnwrap("Hello Swift World".data(using: .utf8), "Data construction failed")
131-
_ = ref.putData(data) { result in
131+
ref.putData(data) { result in
132132
self.assertResultSuccess(result)
133133
ref.delete(completion: nil)
134134
expectation.fulfill()
@@ -140,7 +140,7 @@ class StorageIntegration: XCTestCase {
140140
let expectation = self.expectation(description: #function)
141141
let ref = storage.reference(withPath: "ios/public/testBytesUpload")
142142
let data = try XCTUnwrap("Hello Swift World".data(using: .utf8), "Data construction failed")
143-
_ = ref.putData(data) { result in
143+
ref.putData(data) { result in
144144
self.assertResultSuccess(result)
145145
expectation.fulfill()
146146
}
@@ -151,7 +151,7 @@ class StorageIntegration: XCTestCase {
151151
let expectation = self.expectation(description: #function)
152152
let ref = storage.reference(withPath: "ios/public/-._~!$'()*,=:@&+;")
153153
let data = try XCTUnwrap("Hello Swift World".data(using: .utf8), "Data construction failed")
154-
_ = ref.putData(data) { result in
154+
ref.putData(data) { result in
155155
self.assertResultSuccess(result)
156156
expectation.fulfill()
157157
}
@@ -163,7 +163,7 @@ class StorageIntegration: XCTestCase {
163163
let ref = storage.reference(withPath: "ios/public/testBytesUpload")
164164
let data = try XCTUnwrap("Hello Swift World".data(using: .utf8), "Data construction failed")
165165
DispatchQueue.global(qos: .background).async {
166-
_ = ref.putData(data) { result in
166+
ref.putData(data) { result in
167167
self.assertResultSuccess(result)
168168
expectation.fulfill()
169169
}
@@ -175,7 +175,7 @@ class StorageIntegration: XCTestCase {
175175
let expectation = self.expectation(description: #function)
176176
let ref = storage.reference(withPath: "ios/public/testUnauthenticatedSimplePutEmptyData")
177177
let data = Data()
178-
_ = ref.putData(data) { result in
178+
ref.putData(data) { result in
179179
self.assertResultSuccess(result)
180180
expectation.fulfill()
181181
}
@@ -186,7 +186,7 @@ class StorageIntegration: XCTestCase {
186186
let expectation = self.expectation(description: #function)
187187
let ref = storage.reference(withPath: "ios/private/secretfile.txt")
188188
let data = try XCTUnwrap("Hello Swift World".data(using: .utf8), "Data construction failed")
189-
_ = ref.putData(data) { result in
189+
ref.putData(data) { result in
190190
switch result {
191191
case .success:
192192
XCTFail("Unexpected success from unauthorized putData")
@@ -202,7 +202,7 @@ class StorageIntegration: XCTestCase {
202202
let expectation = self.expectation(description: #function)
203203
let ref = storage.reference(withPath: "ios/private/secretfile.txt")
204204
let data = try XCTUnwrap("Hello Swift World".data(using: .utf8), "Data construction failed")
205-
_ = ref.putData(data) { result in
205+
ref.putData(data) { result in
206206
do {
207207
try _ = result.get() // .failure will throw
208208
} catch {
@@ -257,7 +257,7 @@ class StorageIntegration: XCTestCase {
257257
let tmpDirURL = URL(fileURLWithPath: NSTemporaryDirectory())
258258
let fileURL = tmpDirURL.appendingPathComponent("hello.txt")
259259
try data.write(to: fileURL, options: .atomicWrite)
260-
_ = ref.putFile(from: fileURL) { result in
260+
ref.putFile(from: fileURL) { result in
261261
switch result {
262262
case let .success(metadata):
263263
XCTAssertEqual(fileName, metadata.name)
@@ -278,7 +278,7 @@ class StorageIntegration: XCTestCase {
278278
let ref = storage.reference(withPath: "ios/public/testUnauthenticatedSimplePutDataNoMetadata")
279279
let data = try XCTUnwrap("Hello Swift World".data(using: .utf8), "Data construction failed")
280280

281-
_ = ref.putData(data) { result in
281+
ref.putData(data) { result in
282282
self.assertResultSuccess(result)
283283
expectation.fulfill()
284284
}
@@ -294,7 +294,7 @@ class StorageIntegration: XCTestCase {
294294
let tmpDirURL = URL(fileURLWithPath: NSTemporaryDirectory())
295295
let fileURL = tmpDirURL.appendingPathComponent("hello.txt")
296296
try data.write(to: fileURL, options: .atomicWrite)
297-
_ = ref.putFile(from: fileURL) { result in
297+
ref.putFile(from: fileURL) { result in
298298
self.assertResultSuccess(result)
299299
expectation.fulfill()
300300
}
@@ -305,7 +305,7 @@ class StorageIntegration: XCTestCase {
305305
let expectation = self.expectation(description: #function)
306306

307307
let ref = storage.reference(withPath: "ios/public/1mb")
308-
_ = ref.getData(maxSize: 1024 * 1024) { result in
308+
ref.getData(maxSize: 1024 * 1024) { result in
309309
self.assertResultSuccess(result)
310310
expectation.fulfill()
311311
}
@@ -317,7 +317,7 @@ class StorageIntegration: XCTestCase {
317317

318318
let ref = storage.reference(withPath: "ios/public/1mb")
319319
DispatchQueue.global(qos: .background).async {
320-
_ = ref.getData(maxSize: 1024 * 1024) { result in
320+
ref.getData(maxSize: 1024 * 1024) { result in
321321
self.assertResultSuccess(result)
322322
expectation.fulfill()
323323
}
@@ -329,7 +329,7 @@ class StorageIntegration: XCTestCase {
329329
let expectation = self.expectation(description: #function)
330330

331331
let ref = storage.reference(withPath: "ios/public/1mb")
332-
_ = ref.getData(maxSize: 1024) { result in
332+
ref.getData(maxSize: 1024) { result in
333333
switch result {
334334
case .success:
335335
XCTFail("Unexpected success from getData too small")
@@ -379,7 +379,7 @@ class StorageIntegration: XCTestCase {
379379
let fileURL = tmpDirURL.appendingPathComponent("hello.txt")
380380
let data = try XCTUnwrap("Hello Swift World".data(using: .utf8), "Data construction failed")
381381

382-
_ = ref.putData(data) { result in
382+
ref.putData(data) { result in
383383
switch result {
384384
case .success:
385385
let task = ref.write(toFile: fileURL)

0 commit comments

Comments
 (0)