Explorar el Código

Make getDataWithCompletionBlock snapshot nullable (#9655)

* Make getDataWithCompletionBlock snapshot nullable

* fix DatabaseAPITests

* update changelog

* fix changelog

* breaking change

* Capitalize Swift

Co-authored-by: Ryan Wilson <wilsonryan@google.com>
Jan Wyszynski hace 4 años
padre
commit
8a9e385eb4

+ 3 - 0
FirebaseDatabase/CHANGELOG.md

@@ -1,3 +1,6 @@
+# v8.12.0
+- [fixed] **Breaking change:** Mark `getData()` snapshot as nullable to fix Swift API. (#9655)
+
 # v8.11.0
 - [fixed] Race condition crash in FUtilities.m. (#9096)
 - [fixed] FNextPushId 'successor' crash. (#8790)

+ 3 - 2
FirebaseDatabase/Sources/Api/FIRDatabaseQuery.m

@@ -663,8 +663,9 @@
     });
 }
 
-- (void)getDataWithCompletionBlock:(void (^)(NSError *__nullable error,
-                                             FIRDataSnapshot *snapshot))block {
+- (void)getDataWithCompletionBlock:
+    (void (^)(NSError *__nullable error,
+              FIRDataSnapshot *__nullable snapshot))block {
     dispatch_async([FIRDatabaseQuery sharedQueue], ^{
       [self.repo getData:self withCompletionBlock:block];
     });

+ 2 - 3
FirebaseDatabase/Sources/Core/FRepo.m

@@ -519,9 +519,8 @@
 }
 
 - (void)getData:(FIRDatabaseQuery *)query
-    withCompletionBlock:
-        (void (^_Nonnull)(NSError *__nullable error,
-                          FIRDataSnapshot *__nullable snapshot))block {
+    withCompletionBlock:(void (^)(NSError *__nullable error,
+                                  FIRDataSnapshot *__nullable snapshot))block {
     FQuerySpec *querySpec = [query querySpec];
     id<FNode> node = [self.serverSyncTree getServerValue:[query querySpec]];
     if (node != nil) {

+ 1 - 1
FirebaseDatabase/Sources/FIRDatabaseReference.m

@@ -445,7 +445,7 @@
 
 - (void)getDataWithCompletionBlock:
     (void (^_Nonnull)(NSError *__nullable error,
-                      FIRDataSnapshot *snapshot))block {
+                      FIRDataSnapshot *__nullable snapshot))block {
     [super getDataWithCompletionBlock:block];
 }
 

+ 1 - 1
FirebaseDatabase/Sources/Public/FirebaseDatabase/FIRDatabaseQuery.h

@@ -141,7 +141,7 @@ NS_SWIFT_NAME(DatabaseQuery)
  */
 - (void)getDataWithCompletionBlock:
     (void (^_Nonnull)(NSError *__nullable error,
-                      FIRDataSnapshot *snapshot))block
+                      FIRDataSnapshot *__nullable snapshot))block
     NS_SWIFT_NAME(getData(completion:));
 
 /**

+ 1 - 1
FirebaseDatabase/Sources/Public/FirebaseDatabase/FIRDatabaseReference.h

@@ -377,7 +377,7 @@ priority is meant to be preserved, you should use setValue:andPriority: instead.
  */
 - (void)getDataWithCompletionBlock:
     (void (^_Nonnull)(NSError *__nullable error,
-                      FIRDataSnapshot *snapshot))block
+                      FIRDataSnapshot *__nullable snapshot))block
     NS_SWIFT_NAME(getData(completion:));
 
 #pragma mark - Detaching observers

+ 2 - 2
FirebaseDatabase/Tests/Unit/Swift/DatabaseAPITests.swift

@@ -109,7 +109,7 @@ final class DatabaseAPITests {
     // getData(completion block:)
     databaseQuery.getData { optionalError, dataSnapshot in
       let /* optionalError */ _: Error? = optionalError
-      let /* dataSnapshot */ _: DataSnapshot = dataSnapshot
+      let /* dataSnapshot */ _: DataSnapshot? = dataSnapshot
     }
 
     #if compiler(>=5.5.2) && canImport(_Concurrency)
@@ -388,7 +388,7 @@ final class DatabaseAPITests {
     // getData(completion block:)
     databaseReference.getData { optionalError, dataSnapshot in
       let /* optionalError */ _: Error? = optionalError
-      let /* dataSnapshot */ _: DataSnapshot = dataSnapshot
+      let /* dataSnapshot */ _: DataSnapshot? = dataSnapshot
     }
 
     #if compiler(>=5.5.2) && canImport(_Concurrency)