Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make instanceForProtocol:inContainer: return nullable T #12391

Merged
merged 4 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion FirebaseCore/Extension/FIRComponentType.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion FirebaseCore/Sources/FIRComponentType.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down
12 changes: 8 additions & 4 deletions FirebaseStorage/Sources/Storage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<StorageProvider>.instance(for: StorageProvider.self,
in: app.container)
guard let provider = ComponentType<StorageProvider>.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))
}

Expand All @@ -75,8 +77,10 @@ import FirebaseCore
/// URL.
@objc(storageForApp:URL:)
open class func storage(app: FirebaseApp, url: String) -> Storage {
let provider = ComponentType<StorageProvider>.instance(for: StorageProvider.self,
in: app.container)
guard let provider = ComponentType<StorageProvider>.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))
}

Expand Down
6 changes: 3 additions & 3 deletions FirebaseStorage/Tests/Unit/StorageComponentTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ source 'https://rubygems.org'
# gem 'cocoapods-core', git: "https://github.com/CocoaPods/Core.git", ref: "f7cf05720eab935d7d50e35224d263952176fb53"
# gem 'xcodeproj', git: "https://github.com/CocoaPods/Xcodeproj.git", ref: "eeccae7275645753cbaf45d96fc4b23e4b8b3b9f"

# TODO: Remove this comment after testing
andrewheard marked this conversation as resolved.
Show resolved Hide resolved

gem 'cocoapods', '1.15.2'
gem 'cocoapods-generate', '2.2.5'
gem 'danger', '8.4.5'
Loading