Skip to content

Remove the FirebaseOptions() bare initializer. #6633

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

Merged
merged 3 commits into from
Oct 1, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions FirebaseCore/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
- [changed] The pods developed in this repo are no longer hard coded to be built as static
frameworks. Instead, their linkage will be controlled by the Podfile. Use the Podfile
option `use_frameworks! :linkage => :static` to get the Firebase 6.x linkage behavior. (#2022)
- [removed] Removed broken `FirebaseOptions()` initializer. Use `init(contentsOfFile:)` or
`init(googleAppID:gcmSenderID:)` instead. (#6633)

# Firebase 6.34.0
- [fixed] Removed warning related to missing Analytics framework for non-iOS builds since the
Expand Down
10 changes: 8 additions & 2 deletions FirebaseCore/Sources/FIROptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ - (instancetype)initInternalWithOptionsDictionary:(NSDictionary *)optionsDiction
}

- (id)copyWithZone:(NSZone *)zone {
FIROptions *newOptions = [[[self class] allocWithZone:zone] init];
FIROptions *newOptions = [(FIROptions *)[[self class] allocWithZone:zone]
initInternalWithOptionsDictionary:self.optionsDictionary];
if (newOptions) {
newOptions.optionsDictionary = self.optionsDictionary;
newOptions.deepLinkURLScheme = self.deepLinkURLScheme;
newOptions.appGroupID = self.appGroupID;
newOptions.editingLocked = self.isEditingLocked;
Expand All @@ -173,6 +173,12 @@ - (id)copyWithZone:(NSZone *)zone {

#pragma mark - Public instance methods

- (instancetype)init {
// Unavailable.
[self doesNotRecognizeSelector:_cmd];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we really need this? The initializer marked as unavailable should lead to a compiler error, so I guess it should be enough. Or there is a specific case we would like to cover?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, forgot to link! I was watching the "Refine Objective-C frameworks for Swift" WWDC session and that was the suggestion: https://developer.apple.com/videos/play/wwdc2020/10680/?time=1159

They suggested this to make sure there's no accidental calls there. It also surfaced the copyWithZone: implementation calling the init function when it should have likely called one of the designated initializers.

return nil;
}

- (instancetype)initWithContentsOfFile:(NSString *)plistPath {
self = [super init];
if (self) {
Expand Down
3 changes: 2 additions & 1 deletion FirebaseCore/Sources/Private/FIROptionsInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ extern NSString *const kServiceInfoFileType;
* Initializes the options with dictionary. The above strings are the keys of the dictionary.
* This is the designated initializer.
*/
- (instancetype)initInternalWithOptionsDictionary:(NSDictionary *)serviceInfoDictionary;
- (instancetype)initInternalWithOptionsDictionary:(NSDictionary *)serviceInfoDictionary
NS_DESIGNATED_INITIALIZER;

/**
* defaultOptions and defaultOptionsDictionary are exposed in order to be used in FIRApp and
Expand Down
7 changes: 5 additions & 2 deletions FirebaseCore/Sources/Public/FirebaseCore/FIROptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ NS_SWIFT_NAME(FirebaseOptions)
* FIROptions *options = [[FIROptions alloc] initWithContentsOfFile:filePath];
* Returns nil if the plist file does not exist or is invalid.
*/
- (nullable instancetype)initWithContentsOfFile:(NSString *)plistPath;
- (nullable instancetype)initWithContentsOfFile:(NSString *)plistPath NS_DESIGNATED_INITIALIZER;

/**
* Initializes a customized instance of FIROptions with required fields. Use the mutable properties
Expand All @@ -115,9 +115,12 @@ NS_SWIFT_NAME(FirebaseOptions)
// clang-format off
- (instancetype)initWithGoogleAppID:(NSString *)googleAppID
GCMSenderID:(NSString *)GCMSenderID
NS_SWIFT_NAME(init(googleAppID:gcmSenderID:));
NS_SWIFT_NAME(init(googleAppID:gcmSenderID:)) NS_DESIGNATED_INITIALIZER;
// clang-format on

/** Unavailable. Please use `init(contentsOfFile:)` or `init(googleAppID:gcmSenderID:)` instead. */
- (instancetype)init NS_UNAVAILABLE;

@end

NS_ASSUME_NONNULL_END
4 changes: 3 additions & 1 deletion FirebaseCore/Tests/SwiftUnit/FirebaseAppTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,9 @@ class FirebaseAppTests: XCTestCase {
}

func testFirebaseDataCollectionDefaultEnabled() throws {
let app = FirebaseApp(instanceWithName: "emptyApp", options: FirebaseOptions())
let app = FirebaseApp(instanceWithName: "emptyApp",
options: FirebaseOptions(googleAppID: Constants.Options.googleAppID,
gcmSenderID: Constants.Options.gcmSenderID))

// defaults to true unless otherwise set to no in app's Info.plist
XCTAssertTrue(app.isDataCollectionDefaultEnabled)
Expand Down
5 changes: 3 additions & 2 deletions FirebaseCore/Tests/SwiftUnit/FirebaseOptionsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,9 @@ class FirebaseOptionsTests: XCTestCase {
XCTAssertEqual(defaultOptions1.hash, defaultOptions2.hash)
XCTAssertTrue(defaultOptions1.isEqual(defaultOptions2))

let emptyOptions = FirebaseOptions()
XCTAssertFalse(emptyOptions.isEqual(defaultOptions1))
let plainOptions = FirebaseOptions(googleAppID: Constants.Options.googleAppID,
gcmSenderID: Constants.Options.gcmSenderID)
XCTAssertFalse(plainOptions.isEqual(defaultOptions1))
}

// MARK: - Helpers
Expand Down