mirror of
https://github.com/firebase/firebase-ios-sdk
synced 2026-11-09 22:36:01 +05:45
* Fix previously unknown warnings These become visible once flags are handled uniformly across all Firestore targets in an upcoming build change. * Stop using built-in CMake Framework support CMake has built-in support for building Framework bundles (briefly: bundles of libraries, associated headers, and resources) but this doesn't work well for our needs. 1. In CMake 3.5.1 (our earliest supported CMake version) it doesn't copy headers properly at build time. 2. Even up to CMake 3.15.5, CMake doesn't handle link-line multiplicity correctly. CMake passes the static library location within the framework and this seems to cause the linker to mishandle Objective-C metaclass information resulting in duplicate symbols. Building with `-framework` flags works correctly. Previously we partially worked around the latter problem by building some frameworks as shared instead of static frameworks, but this is problematic because this mode of operation isn't actually intended and is unsupported as far as the rest of Firebase is concerned. This turned out to be fragile though and while refactoring libraries this workaround broke. Rather than piling on additional workarounds, this change converts the frameworks to simple library targets and emulates framework imports through include paths. Additionally, this starts refactoring our cmake helper functions to make them more like built-in functions. This makes it possible to freely use different CMake features that were made difficult by trying to wrap everything up in a single CMake command. * style.sh generated changes * Review feedback * More review feedback
133 lines
4.6 KiB
Plaintext
133 lines
4.6 KiB
Plaintext
/*
|
|
* Copyright 2017 Google
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
#import "FIRCollectionReference.h"
|
|
|
|
#include <utility>
|
|
|
|
#import "Firestore/Source/API/FIRDocumentReference+Internal.h"
|
|
#import "Firestore/Source/API/FIRFirestore+Internal.h"
|
|
#import "Firestore/Source/API/FIRQuery+Internal.h"
|
|
#import "Firestore/Source/API/FSTUserDataConverter.h"
|
|
|
|
#include "Firestore/core/src/firebase/firestore/api/collection_reference.h"
|
|
#include "Firestore/core/src/firebase/firestore/api/document_reference.h"
|
|
#include "Firestore/core/src/firebase/firestore/core/user_data.h"
|
|
#include "Firestore/core/src/firebase/firestore/model/resource_path.h"
|
|
#include "Firestore/core/src/firebase/firestore/util/error_apple.h"
|
|
#include "Firestore/core/src/firebase/firestore/util/exception.h"
|
|
#include "Firestore/core/src/firebase/firestore/util/string_apple.h"
|
|
|
|
namespace util = firebase::firestore::util;
|
|
using firebase::firestore::api::CollectionReference;
|
|
using firebase::firestore::api::DocumentReference;
|
|
using firebase::firestore::core::ParsedSetData;
|
|
using firebase::firestore::model::ResourcePath;
|
|
using firebase::firestore::util::ThrowInvalidArgument;
|
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
@implementation FIRCollectionReference
|
|
|
|
- (instancetype)initWithReference:(CollectionReference &&)reference {
|
|
return [super initWithQuery:std::move(reference)];
|
|
}
|
|
|
|
- (instancetype)initWithPath:(ResourcePath)path
|
|
firestore:(std::shared_ptr<api::Firestore>)firestore {
|
|
CollectionReference ref(std::move(path), std::move(firestore));
|
|
return [self initWithReference:std::move(ref)];
|
|
}
|
|
|
|
// Override the designated initializer from the super class.
|
|
- (instancetype)initWithQuery:(api::Query &&)query {
|
|
(void)query;
|
|
|
|
HARD_FAIL("Use FIRCollectionReference initWithPath: initializer.");
|
|
}
|
|
|
|
// NSObject Methods
|
|
- (BOOL)isEqual:(nullable id)other {
|
|
if (other == self) return YES;
|
|
if (![[other class] isEqual:[self class]]) return NO;
|
|
|
|
return [self isEqualToReference:other];
|
|
}
|
|
|
|
- (BOOL)isEqualToReference:(nullable FIRCollectionReference *)otherReference {
|
|
if (self == otherReference) return YES;
|
|
if (otherReference == nil) return NO;
|
|
return self.reference == otherReference.reference;
|
|
}
|
|
|
|
- (NSUInteger)hash {
|
|
return self.reference.Hash();
|
|
}
|
|
|
|
- (const CollectionReference &)reference {
|
|
// TODO(wilhuff): Use some alternate method for doing this.
|
|
//
|
|
// Casting from Query& to CollectionReference& when the value is actually a
|
|
// Query violates aliasing rules and is technically undefined behavior.
|
|
// Nevertheless this works on Clang so this is good enough for now.
|
|
return static_cast<const CollectionReference &>(self.apiQuery);
|
|
}
|
|
|
|
- (NSString *)collectionID {
|
|
return util::MakeNSString(self.reference.collection_id());
|
|
}
|
|
|
|
- (FIRDocumentReference *_Nullable)parent {
|
|
absl::optional<DocumentReference> parent = self.reference.parent();
|
|
if (!parent) {
|
|
return nil;
|
|
}
|
|
return [[FIRDocumentReference alloc] initWithReference:std::move(*parent)];
|
|
}
|
|
|
|
- (NSString *)path {
|
|
return util::MakeNSString(self.reference.path());
|
|
}
|
|
|
|
- (FIRDocumentReference *)documentWithPath:(NSString *)documentPath {
|
|
if (!documentPath) {
|
|
ThrowInvalidArgument("Document path cannot be nil.");
|
|
}
|
|
DocumentReference child = self.reference.Document(util::MakeString(documentPath));
|
|
return [[FIRDocumentReference alloc] initWithReference:std::move(child)];
|
|
}
|
|
|
|
- (FIRDocumentReference *)addDocumentWithData:(NSDictionary<NSString *, id> *)data {
|
|
return [self addDocumentWithData:data completion:nil];
|
|
}
|
|
|
|
- (FIRDocumentReference *)addDocumentWithData:(NSDictionary<NSString *, id> *)data
|
|
completion:
|
|
(nullable void (^)(NSError *_Nullable error))completion {
|
|
ParsedSetData parsed = [self.firestore.dataConverter parsedSetData:data];
|
|
DocumentReference docRef =
|
|
self.reference.AddDocument(std::move(parsed), util::MakeCallback(completion));
|
|
return [[FIRDocumentReference alloc] initWithReference:std::move(docRef)];
|
|
}
|
|
|
|
- (FIRDocumentReference *)documentWithAutoID {
|
|
return [[FIRDocumentReference alloc] initWithReference:self.reference.Document()];
|
|
}
|
|
|
|
@end
|
|
|
|
NS_ASSUME_NONNULL_END
|