diff --git a/FirebaseCore/Extension/FIRComponentType.h b/FirebaseCore/Extension/FIRComponentType.h index 6f2aca7b863..c69085d1983 100644 --- a/FirebaseCore/Extension/FIRComponentType.h +++ b/FirebaseCore/Extension/FIRComponentType.h @@ -27,7 +27,8 @@ NS_SWIFT_NAME(ComponentType) /// Do not use directly. A factory method to retrieve an instance that provides a specific /// functionality. -+ (T)instanceForProtocol:(Protocol *)protocol inContainer:(FIRComponentContainer *)container; ++ (nullable T)instanceForProtocol:(Protocol *)protocol + inContainer:(FIRComponentContainer *)container; @end diff --git a/FirebaseCore/Sources/FIRComponentType.m b/FirebaseCore/Sources/FIRComponentType.m index c9cd2ad2c2c..2204fd65b32 100644 --- a/FirebaseCore/Sources/FIRComponentType.m +++ b/FirebaseCore/Sources/FIRComponentType.m @@ -20,7 +20,8 @@ @implementation FIRComponentType -+ (id)instanceForProtocol:(Protocol *)protocol inContainer:(FIRComponentContainer *)container { ++ (nullable id)instanceForProtocol:(Protocol *)protocol + inContainer:(FIRComponentContainer *)container { // Forward the call to the container. return [container instanceForProtocol:protocol]; } diff --git a/FirebaseStorage/Sources/Storage.swift b/FirebaseStorage/Sources/Storage.swift index 79d18dfa4f6..16792fd1d80 100644 --- a/FirebaseStorage/Sources/Storage.swift +++ b/FirebaseStorage/Sources/Storage.swift @@ -61,8 +61,10 @@ import FirebaseCore /// - Parameter app: The custom `FirebaseApp` used for initialization. /// - Returns: A `Storage` instance, configured with the custom `FirebaseApp`. @objc(storageForApp:) open class func storage(app: FirebaseApp) -> Storage { - let provider = ComponentType.instance(for: StorageProvider.self, - in: app.container) + guard let provider = ComponentType.instance(for: StorageProvider.self, + in: app.container) else { + fatalError("No \(StorageProvider.self) instance found for Firebase app: \(app.name)") + } return provider.storage(for: Storage.bucket(for: app)) } @@ -75,8 +77,10 @@ import FirebaseCore /// URL. @objc(storageForApp:URL:) open class func storage(app: FirebaseApp, url: String) -> Storage { - let provider = ComponentType.instance(for: StorageProvider.self, - in: app.container) + guard let provider = ComponentType.instance(for: StorageProvider.self, + in: app.container) else { + fatalError("No \(StorageProvider.self) instance found for Firebase app: \(app.name)") + } return provider.storage(for: Storage.bucket(for: app, urlString: url)) } diff --git a/FirebaseStorage/Tests/Unit/StorageComponentTests.swift b/FirebaseStorage/Tests/Unit/StorageComponentTests.swift index dce5d75fe0d..a7851fb9479 100644 --- a/FirebaseStorage/Tests/Unit/StorageComponentTests.swift +++ b/FirebaseStorage/Tests/Unit/StorageComponentTests.swift @@ -70,14 +70,14 @@ class StorageComponentTests: StorageTestHelpers { in: container) XCTAssertNotNil(provider) - let storage1 = provider.storage(for: "randomBucket") - let storage2 = provider.storage(for: "randomBucket") + let storage1 = provider?.storage(for: "randomBucket") + let storage2 = provider?.storage(for: "randomBucket") XCTAssertNotNil(storage1) // Ensure they're the same instance. XCTAssert(storage1 === storage2) - let storage3 = provider.storage(for: "differentBucket") + let storage3 = provider?.storage(for: "differentBucket") XCTAssertNotNil(storage3) XCTAssert(storage1 !== storage3)