Skip to content

Commit 1fc4e50

Browse files
paulb777ncooke3
andauthored
Merge 9715 and 9720 to master (#9719)
* Missing NSObject overrides and tests (#9715) * [v9] Improve clarity of zip integration instructions (#9720) Co-authored-by: Nick Cooke <[email protected]>
1 parent 5238f50 commit 1fc4e50

File tree

5 files changed

+150
-16
lines changed

5 files changed

+150
-16
lines changed

FirebaseStorage/Sources/StorageListResult.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,18 @@ import FirebaseStorageInternal
4040
*/
4141
@objc public let pageToken: String?
4242

43+
// MARK: - NSObject overrides
44+
45+
@objc override open func copy() -> Any {
46+
return StorageListResult(impl.copy() as! FIRIMPLStorageListResult)
47+
}
48+
49+
// MARK: - Internal APIs
50+
51+
internal let impl: FIRIMPLStorageListResult
52+
4353
internal init(_ impl: FIRIMPLStorageListResult) {
54+
self.impl = impl
4455
prefixes = impl.prefixes.map { StorageReference($0) }
4556
items = impl.items.map { StorageReference($0) }
4657
pageToken = impl.pageToken

FirebaseStorage/Sources/StorageMetadata.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,27 @@ import FirebaseStorageInternal
182182
self.init(impl: FIRIMPLStorageMetadata(dictionary: dictionary)!)
183183
}
184184

185+
// MARK: - NSObject overrides
186+
187+
@objc override open func copy() -> Any {
188+
return StorageMetadata(impl: impl.copy() as! FIRIMPLStorageMetadata)
189+
}
190+
191+
@objc override open func isEqual(_ object: Any?) -> Bool {
192+
guard let ref = object as? StorageMetadata else {
193+
return false
194+
}
195+
return impl.isEqual(ref.impl)
196+
}
197+
198+
@objc override public var hash: Int {
199+
return impl.hash
200+
}
201+
202+
@objc override public var description: String {
203+
return impl.description
204+
}
205+
185206
// MARK: - Internal APIs
186207

187208
internal let impl: FIRIMPLStorageMetadata
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Copyright 2022 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import Foundation
16+
17+
import FirebaseStorage
18+
19+
import XCTest
20+
21+
class StorageMetadataTests: XCTestCase {
22+
func testReflexiveMetadataEquality() {
23+
let metaDict = ["bucket": "bucket", "name": "/path/to/file"]
24+
let metadata0 = StorageMetadata(dictionary: metaDict)
25+
let metadata1 = metadata0
26+
XCTAssertEqual(metadata0, metadata1)
27+
}
28+
29+
func testMetadataEquality() {
30+
let metaDict = [
31+
"bucket": "bucket",
32+
"name": "/path/to/file",
33+
"md5Hash": "d41d8cd98f00b204e9800998ecf8427e",
34+
]
35+
let metadata0 = StorageMetadata(dictionary: metaDict)
36+
let metadata1 = StorageMetadata(dictionary: metaDict)
37+
XCTAssertEqual(metadata0, metadata1)
38+
}
39+
40+
func testMetadataMd5Inequality() {
41+
let metaDict0 = ["md5Hash": "d41d8cd98f00b204e9800998ecf8427e"]
42+
let metaDict1 = ["md5Hash": "d41d8cd98f00b204e9800998ecf8427f"]
43+
let metadata0 = StorageMetadata(dictionary: metaDict0)
44+
let metadata1 = StorageMetadata(dictionary: metaDict1)
45+
XCTAssertNotEqual(metadata0, metadata1)
46+
}
47+
48+
func testMetadataCopy() {
49+
let metaDict = [
50+
"bucket": "bucket",
51+
"name": "/path/to/file",
52+
"md5Hash": "d41d8cd98f00b204e9800998ecf8427e",
53+
]
54+
let metadata0 = StorageMetadata(dictionary: metaDict)
55+
let metadata1 = metadata0.copy() as? StorageMetadata
56+
// Verify that copied object has a new reference.
57+
XCTAssertFalse(metadata0 === metadata1)
58+
XCTAssertEqual(metadata0, metadata1)
59+
}
60+
}

FirebaseStorageInternal/Tests/Integration/FIRStorageIntegrationTests.m

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ - (void)testSameInstanceCustomBucket {
149149
XCTAssertEqual(storage1, storage2);
150150
}
151151

152-
- (void)testDiffferentInstance {
152+
- (void)testDifferentInstance {
153153
FIRStorage *storage1 = [FIRStorage storageForApp:self.app];
154154
FIRStorage *storage2 = [FIRStorage storageForApp:self.app URL:@"gs://foo-bar.appspot.com"];
155155
XCTAssertNotEqual(storage1, storage2);
@@ -175,6 +175,22 @@ - (void)testGetMetadata {
175175
[self waitForExpectations];
176176
}
177177

178+
- (void)testCopyMetadata {
179+
XCTestExpectation *expectation = [self expectationWithDescription:@"testGetMetadata"];
180+
FIRStorageReference *ref = [self.storage.reference child:@"ios/public/1mb"];
181+
182+
[ref metadataWithCompletion:^(FIRStorageMetadata *metadata, NSError *error) {
183+
XCTAssertNotNil(metadata, "Metadata should not be nil");
184+
XCTAssertNil(error, "Error should be nil");
185+
FIRStorageMetadata *metadata2 = metadata.copy;
186+
XCTAssertNotEqual(metadata, metadata2);
187+
XCTAssertEqualObjects(metadata, metadata2);
188+
[expectation fulfill];
189+
}];
190+
191+
[self waitForExpectations];
192+
}
193+
178194
- (void)testDelete {
179195
XCTestExpectation *expectation = [self expectationWithDescription:@"testDelete"];
180196

@@ -829,6 +845,25 @@ - (void)testListFilesAtRoot {
829845
[self waitForExpectations];
830846
}
831847

848+
- (void)testCopyListResult {
849+
XCTestExpectation *expectation = [self expectationWithDescription:@"testCopyListResult"];
850+
851+
FIRStorageReference *ref = [self.storage referenceWithPath:@""];
852+
853+
[ref listAllWithCompletion:^(FIRStorageListResult *_Nullable listResult,
854+
NSError *_Nullable error) {
855+
XCTAssertNotNil(listResult);
856+
XCTAssertNil(error);
857+
XCTAssertNil(listResult.pageToken);
858+
FIRStorageListResult *listResult2 = listResult.copy;
859+
XCTAssertEqual(listResult.pageToken, listResult2.pageToken);
860+
XCTAssertNotEqual(listResult, listResult2);
861+
[expectation fulfill];
862+
}];
863+
864+
[self waitForExpectations];
865+
}
866+
832867
- (void)waitForExpectations {
833868
[self waitForExpectationsWithTimeout:kFIRStorageIntegrationTestTimeout
834869
handler:^(NSError *_Nullable error) {

ReleaseTooling/Template/README.md

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ To integrate a Firebase SDK with your app:
2424
want the framework to be added to has a checkmark next to it, and that
2525
you've selected "Copy items if needed".
2626

27-
*To disable AdId support, do not copy
28-
`GoogleAppMeasurementIdentitySupport.xcframework`.*
27+
> To disable AdId support, do not copy
28+
> `GoogleAppMeasurementIdentitySupport.xcframework`.
2929
30-
*If the app does not use any Firebase Swift specific APIs, you do not need
31-
to copy any xcframeworks whose name includes "Swift" for this and the next
32-
step.*
30+
> If the app does not use any Firebase Swift specific APIs, you do not need
31+
> to copy any xcframeworks whose name includes `Swift` for this and the next
32+
> step.
3333
3434
6. Drag each framework from the directory named after the SDK into the Project
3535
Navigator pane. Note that there may be no additional frameworks, in which
@@ -38,22 +38,25 @@ To integrate a Firebase SDK with your app:
3838
box that appears, make sure the target you want this framework to be added to
3939
has a checkmark next to it, and that you've selected "Copy items if needed."
4040

41-
*Do not add the Firebase frameworks to the "Embed Frameworks" Xcode build
42-
phase. The Firebase frameworks are not embedded dynamic frameworks, but are
43-
[static frameworks](https://www.raywenderlich.com/65964/create-a-framework-for-ios)
44-
which cannot be embedded into your application's bundle.*
41+
> Do not add the Firebase frameworks to the **Embed Frameworks** Xcode build
42+
> phase. The Firebase frameworks are not embedded dynamic frameworks, but are
43+
> [static frameworks](https://www.raywenderlich.com/65964/create-a-framework-for-ios)
44+
> which cannot be embedded into your application's bundle.
4545
4646
7. If the SDK has resources, go into the Resources folders, which will be in
4747
the SDK folder. Drag all of those resources into the Project Navigator, just
4848
like the frameworks, again making sure that the target you want to add these
4949
resources to has a checkmark next to it, and that you've selected "Copy items
5050
if needed".
51-
8. Add the -ObjC flag to "Other Linker Settings":
52-
a. In your project settings, open the Settings panel for your target
53-
b. Go to the Build Settings tab and find the "Other Linker Flags" setting
54-
in the Linking section.
55-
c. Double-click the setting, click the '+' button, and add "-ObjC" (without
56-
quotes)
51+
8. Add the `-ObjC` flag to **Other Linker Settings**:
52+
53+
a. In your project settings, open the **Settings** panel for your target.
54+
55+
b. Go to the Build Settings tab and find the **Other Linker Flags** setting
56+
in the **Linking** section.
57+
58+
c. Double-click the setting, click the '+' button, and add `-ObjC`
59+
5760
9. Drag the `Firebase.h` header in this directory into your project. This will
5861
allow you to `#import "Firebase.h"` and start using any Firebase SDK that you
5962
have.
@@ -64,6 +67,10 @@ To integrate a Firebase SDK with your app:
6467
a dummy Swift file to the app to prevent Swift system library missing
6568
symbol linker errors. See
6669
https://forums.swift.org/t/using-binary-swift-sdks-from-non-swift-apps/55989.
70+
71+
> ⚠ If prompted with the option to create a corresponding bridging header
72+
> for the new Swift file, select **Don't create**.
73+
6774
12. You're done! Compile your target and start using Firebase.
6875

6976
If you want to add another SDK, repeat the steps above with the xcframeworks for

0 commit comments

Comments
 (0)