This commit is contained in:
Yao
2024-12-20 17:49:45 +08:00
parent 86b0363ce1
commit 654d456c7d
7011 changed files with 1705926 additions and 7 deletions

View File

@@ -0,0 +1,114 @@
/*
* Copyright 2023 Google LLC
*
* 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 <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@class FIRFieldPath;
/**
* Represents an aggregation that can be performed by Firestore.
*/
NS_SWIFT_NAME(AggregateField)
@interface FIRAggregateField : NSObject
/** :nodoc: */
- (instancetype)init NS_UNAVAILABLE;
/**
* Create an `AggregateField` object that can be used to compute the count of
* documents in the result set of a query.
*
* The result of a count operation will always be a 64-bit integer value.
*
* @return `AggregateField` object that can be used to compute the count of
* documents in the result set of a query.
*/
+ (instancetype)aggregateFieldForCount NS_SWIFT_NAME(count());
/**
* Create an `AggregateField` object that can be used to compute the sum of
* a specified field over a range of documents in the result set of a query.
*
* The result of a sum operation will always be a 64-bit integer value, a double, or NaN.
*
* - Summing over zero documents or fields will result in 0L.
* - Summing over NaN will result in a double value representing NaN.
* - A sum that overflows the maximum representable 64-bit integer value will result in a double
* return value. This may result in lost precision of the result.
* - A sum that overflows the maximum representable double value will result in a double return
* value representing infinity.
*
* @param field Specifies the field to sum across the result set.
* @return `AggregateField` object that can be used to compute the sum of
* a specified field over a range of documents in the result set of a query.
*/
+ (instancetype)aggregateFieldForSumOfField:(NSString *)field NS_SWIFT_NAME(sum(_:));
/**
* Create an `AggregateField` object that can be used to compute the sum of
* a specified field over a range of documents in the result set of a query.
*
* The result of a sum operation will always be a 64-bit integer value, a double, or NaN.
*
* - Summing over zero documents or fields will result in 0L.
* - Summing over NaN will result in a double value representing NaN.
* - A sum that overflows the maximum representable 64-bit integer value will result in a double
* return value. This may result in lost precision of the result.
* - A sum that overflows the maximum representable double value will result in a double return
* value representing infinity.
*
* @param fieldPath Specifies the field to sum across the result set.
* @return `AggregateField` object that can be used to compute the sum of
* a specified field over a range of documents in the result set of a query.
*/
+ (instancetype)aggregateFieldForSumOfFieldPath:(FIRFieldPath *)fieldPath NS_SWIFT_NAME(sum(_:));
/**
* Create an `AggregateField` object that can be used to compute the average of
* a specified field over a range of documents in the result set of a query.
*
* The result of an average operation will always be a double or NaN.
*
* - Averaging over zero documents or fields will result in a double value representing NaN.
* - Averaging over NaN will result in a double value representing NaN.
*
* @param field Specifies the field to average across the result set.
* @return `AggregateField` object that can be used to compute the average of
* a specified field over a range of documents in the result set of a query.
*/
+ (instancetype)aggregateFieldForAverageOfField:(NSString *)field NS_SWIFT_NAME(average(_:));
/**
* Create an `AggregateField` object that can be used to compute the average of
* a specified field over a range of documents in the result set of a query.
*
* The result of an average operation will always be a double or NaN.
*
* - Averaging over zero documents or fields will result in a double value representing NaN.
* - Averaging over NaN will result in a double value representing NaN.
*
* @param fieldPath Specifies the field to average across the result set.
* @return `AggregateField` object that can be used to compute the average of
* a specified field over a range of documents in the result set of a query.
*/
+ (instancetype)aggregateFieldForAverageOfFieldPath:(FIRFieldPath *)fieldPath
NS_SWIFT_NAME(average(_:));
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,51 @@
/*
* Copyright 2022 Google LLC
*
* 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 <Foundation/Foundation.h>
#import "FIRAggregateSource.h"
NS_ASSUME_NONNULL_BEGIN
@class FIRQuery;
@class FIRAggregateQuerySnapshot;
/**
* A query that calculates aggregations over an underlying query.
*/
NS_SWIFT_NAME(AggregateQuery)
@interface FIRAggregateQuery : NSObject
/** :nodoc: */
- (instancetype)init __attribute__((unavailable("FIRAggregateQuery cannot be created directly.")));
/** The query whose aggregations will be calculated by this object. */
@property(nonatomic, readonly) FIRQuery *query;
/**
* Executes this query.
*
* @param source The source from which to acquire the aggregate results.
* @param completion a block to execute once the results have been successfully read.
* snapshot will be `nil` only if error is `non-nil`.
*/
- (void)aggregationWithSource:(FIRAggregateSource)source
completion:(void (^)(FIRAggregateQuerySnapshot *_Nullable snapshot,
NSError *_Nullable error))completion
NS_SWIFT_NAME(getAggregation(source:completion:));
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,58 @@
/*
* Copyright 2022 Google LLC
*
* 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 <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@class FIRAggregateQuery;
@class FIRAggregateField;
/**
* The results of executing an `AggregateQuery`.
*/
NS_SWIFT_NAME(AggregateQuerySnapshot)
@interface FIRAggregateQuerySnapshot : NSObject
/** :nodoc: */
- (instancetype)init
__attribute__((unavailable("FIRAggregateQuerySnapshot cannot be created directly.")));
/** The query that was executed to produce this result. */
@property(nonatomic, readonly) FIRAggregateQuery* query;
/** The number of documents in the result set of the underlying query. */
@property(nonatomic, readonly) NSNumber* count;
/**
* Gets the aggregate result for the specified aggregate field without loss of precision. No
* coercion of data types or values is performed.
*
* See the `AggregateField` class for the expected aggregate result values and types. Numeric
* aggregate results will be boxed in an `NSNumber`.
*
* @param aggregateField An instance of `AggregateField` that specifies which aggregate result to
* return.
* @return Returns the aggregate result from the server without loss of precision.
* @warning Throws an `InvalidArgument` exception if the aggregate field was not requested in the
* `AggregateQuery`.
* @see `AggregateField`
*/
- (id)valueForAggregateField:(FIRAggregateField*)aggregateField NS_SWIFT_NAME(get(_:));
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,42 @@
/*
* Copyright 2022 Google LLC
*
* 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 <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
/**
* The sources from which an `AggregateQuery` can retrieve its results.
*
* See `AggregateQuery.getAggregation(source:completion:)`.
*/
typedef NS_ENUM(NSUInteger, FIRAggregateSource) {
/**
* Perform the aggregation on the server and download the result.
*
* The result received from the server is presented, unaltered, without considering any local
* state. That is, documents in the local cache are not taken into consideration, neither are
* local modifications not yet synchronized with the server. Previously-downloaded results, if
* any, are not used. Every request using this source necessarily involves a round trip to the
* server.
*
* The `AggregateQuery` will fail if the server cannot be reached, such as if the client is
* offline.
*/
FIRAggregateSourceServer,
} NS_SWIFT_NAME(AggregateSource);
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,100 @@
/*
* 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 <Foundation/Foundation.h>
#import "FIRQuery.h"
NS_ASSUME_NONNULL_BEGIN
@class FIRDocumentReference;
/**
* A `CollectionReference` object can be used for adding documents, getting document references,
* and querying for documents (using the methods inherited from `Query`).
*/
NS_SWIFT_NAME(CollectionReference)
@interface FIRCollectionReference : FIRQuery
/** :nodoc: */
- (id)init __attribute__((unavailable("FIRCollectionReference cannot be created directly.")));
/** ID of the referenced collection. */
@property(nonatomic, strong, readonly) NSString *collectionID;
/**
* For subcollections, `parent` returns the containing `DocumentReference`. For root collections,
* `nil` is returned.
*/
@property(nonatomic, strong, nullable, readonly) FIRDocumentReference *parent;
/**
* A string containing the slash-separated path to this this `CollectionReference` (relative to the
* root of the database).
*/
@property(nonatomic, strong, readonly) NSString *path;
/**
* Returns a `DocumentReference` pointing to a new document with an auto-generated ID.
*
* @return A `DocumentReference` pointing to a new document with an auto-generated ID.
*/
- (FIRDocumentReference *)documentWithAutoID NS_SWIFT_NAME(document());
/**
* Gets a `DocumentReference` referring to the document at the specified path, relative to this
* collection's own path.
*
* @param documentPath The slash-separated relative path of the document for which to get a
* `DocumentReference`.
*
* @return The `DocumentReference` for the specified document path.
*/
- (FIRDocumentReference *)documentWithPath:(NSString *)documentPath NS_SWIFT_NAME(document(_:));
/**
* Adds a new document to this collection with the specified data, assigning it a document ID
* automatically.
*
* @param data A `Dictionary` containing the data for the new document.
*
* @return A `DocumentReference` pointing to the newly created document.
*/
- (FIRDocumentReference *)addDocumentWithData:(NSDictionary<NSString *, id> *)data
NS_SWIFT_NAME(addDocument(data:));
/**
* Adds a new document to this collection with the specified data, assigning it a document ID
* automatically.
*
* @param data A `Dictionary` containing the data for the new document.
* @param completion A block to execute once the document has been successfully written to
* the server. This block will not be called while the client is offline, though local
* changes will be visible immediately.
*
* @return A `DocumentReference` pointing to the newly created document.
*/
// clang-format off
// clang-format breaks the NS_SWIFT_NAME attribute
- (FIRDocumentReference *)addDocumentWithData:(NSDictionary<NSString *, id> *)data
completion:
(nullable void (^)(NSError *_Nullable error))completion
NS_SWIFT_NAME(addDocument(data:completion:));
// clang-format on
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,74 @@
/*
* 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 <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@class FIRQueryDocumentSnapshot;
#if defined(NS_CLOSED_ENUM)
/** An enumeration of document change types. */
typedef NS_CLOSED_ENUM(NSInteger, FIRDocumentChangeType)
#else
/** An enumeration of document change types. */
typedef NS_ENUM(NSInteger, FIRDocumentChangeType)
#endif
{
/** Indicates a new document was added to the set of documents matching the query. */
FIRDocumentChangeTypeAdded,
/** Indicates a document within the query was modified. */
FIRDocumentChangeTypeModified,
/**
* Indicates a document within the query was removed (either deleted or no longer matches
* the query.
*/
FIRDocumentChangeTypeRemoved
} NS_SWIFT_NAME(DocumentChangeType);
/**
* A `DocumentChange` represents a change to the documents matching a query. It contains the
* document affected and the type of change that occurred (added, modified, or removed).
*/
NS_SWIFT_NAME(DocumentChange)
@interface FIRDocumentChange : NSObject
/** :nodoc: */
- (id)init __attribute__((unavailable("FIRDocumentChange cannot be created directly.")));
/** The type of change that occurred (added, modified, or removed). */
@property(nonatomic, readonly) FIRDocumentChangeType type;
/** The document affected by this change. */
@property(nonatomic, strong, readonly) FIRQueryDocumentSnapshot *document;
/**
* The index of the changed document in the result set immediately prior to this `DocumentChange`
* (i.e. supposing that all prior `DocumentChange` objects have been applied). `NSNotFound` for
* `DocumentChangeTypeAdded` events.
*/
@property(nonatomic, readonly) NSUInteger oldIndex;
/**
* The index of the changed document in the result set immediately after this `DocumentChange`
* (i.e. supposing that all prior `DocumentChange` objects and the current `DocumentChange` object
* have been applied). `NSNotFound` for `DocumentChangeTypeRemoved` events.
*/
@property(nonatomic, readonly) NSUInteger newIndex;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,292 @@
/*
* 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 <Foundation/Foundation.h>
#import "FIRFirestoreSource.h"
#import "FIRListenerRegistration.h"
#import "FIRSnapshotListenOptions.h"
@class FIRCollectionReference;
@class FIRDocumentSnapshot;
@class FIRFirestore;
NS_ASSUME_NONNULL_BEGIN
/**
* A block type used to handle snapshot updates.
*/
typedef void (^FIRDocumentSnapshotBlock)(FIRDocumentSnapshot *_Nullable snapshot,
NSError *_Nullable error)
NS_SWIFT_UNAVAILABLE("Use Swift's closure syntax instead.");
/**
* A `DocumentReference` refers to a document location in a Firestore database and can be
* used to write, read, or listen to the location. The document at the referenced location
* may or may not exist. A `DocumentReference` can also be used to create a `CollectionReference` to
* a subcollection.
*/
NS_SWIFT_NAME(DocumentReference)
@interface FIRDocumentReference : NSObject
/** :nodoc: */
- (instancetype)init
__attribute__((unavailable("FIRDocumentReference cannot be created directly.")));
/** The ID of the document referred to. */
@property(nonatomic, strong, readonly) NSString *documentID;
/** A reference to the collection to which this `DocumentReference` belongs. */
@property(nonatomic, strong, readonly) FIRCollectionReference *parent;
/** The `Firestore` for the Firestore database (useful for performing transactions, etc.). */
@property(nonatomic, strong, readonly) FIRFirestore *firestore;
/**
* A string representing the path of the referenced document (relative to the root of the
* database).
*/
@property(nonatomic, strong, readonly) NSString *path;
/**
* Gets a `CollectionReference` referring to the collection at the specified path, relative to this
* document.
*
* @param collectionPath The slash-separated relative path of the collection for which to get a
* `CollectionReference`.
*
* @return The `CollectionReference` at the specified _collectionPath_.
*/
- (FIRCollectionReference *)collectionWithPath:(NSString *)collectionPath
NS_SWIFT_NAME(collection(_:));
#pragma mark - Writing Data
/**
* Writes to the document referred to by `DocumentReference`. If the document doesn't yet exist,
* this method creates it and then sets the data. If the document exists, this method overwrites
* the document data with the new values.
*
* @param documentData A `Dictionary` that contains the fields and data to write to the
* document.
*/
- (void)setData:(NSDictionary<NSString *, id> *)documentData;
/**
* Writes to the document referred to by this `DocumentReference`. If the document does not yet
* exist, it will be created. If you pass `merge:true`, the provided data will be merged into
* any existing document.
*
* @param documentData A `Dictionary` that contains the fields and data to write to the
* document.
* @param merge Whether to merge the provided data into any existing document. If enabled,
* all omitted fields remain untouched. If your input sets any field to an empty dictionary, any
* nested field is overwritten.
*/
- (void)setData:(NSDictionary<NSString *, id> *)documentData merge:(BOOL)merge;
/**
* Writes to the document referred to by `document` and only replace the fields
* specified under `mergeFields`. Any field that is not specified in `mergeFields`
* is ignored and remains untouched. If the document doesn't yet exist,
* this method creates it and then sets the data.
*
* It is an error to include a field in `mergeFields` that does not have a corresponding
* value in the `data` dictionary.
*
* @param documentData A `Dictionary` containing the fields that make up the document
* to be written.
* @param mergeFields An `Array` that contains a list of `String` or `FieldPath` elements
* specifying which fields to merge. Fields can contain dots to reference nested fields within
* the document. If your input sets any field to an empty dictionary, any nested field is
* overwritten.
*/
- (void)setData:(NSDictionary<NSString *, id> *)documentData mergeFields:(NSArray<id> *)mergeFields;
/**
* Overwrites the document referred to by this `DocumentReference`. If no document exists, it
* is created. If a document already exists, it is overwritten.
*
* @param documentData A `Dictionary` containing the fields that make up the document
* to be written.
* @param completion A block to execute once the document has been successfully written to the
* server. This block will not be called while the client is offline, though local
* changes will be visible immediately.
*/
- (void)setData:(NSDictionary<NSString *, id> *)documentData
completion:(nullable void (^)(NSError *_Nullable error))completion;
/**
* Writes to the document referred to by this `DocumentReference`. If the document does not yet
* exist, it will be created. If you pass `merge:true`, the provided data will be merged into
* any existing document.
*
* @param documentData A `Dictionary` containing the fields that make up the document
* to be written.
* @param merge Whether to merge the provided data into any existing document. If your input sets
* any field to an empty dictionary, any nested field is overwritten.
* @param completion A block to execute once the document has been successfully written to the
* server. This block will not be called while the client is offline, though local
* changes will be visible immediately.
*/
- (void)setData:(NSDictionary<NSString *, id> *)documentData
merge:(BOOL)merge
completion:(nullable void (^)(NSError *_Nullable error))completion;
/**
* Writes to the document referred to by `document` and only replace the fields
* specified under `mergeFields`. Any field that is not specified in `mergeFields`
* is ignored and remains untouched. If the document doesn't yet exist,
* this method creates it and then sets the data.
*
* It is an error to include a field in `mergeFields` that does not have a corresponding
* value in the `data` dictionary.
*
* @param documentData A `Dictionary` containing the fields that make up the document
* to be written.
* @param mergeFields An `Array` that contains a list of `String` or `FieldPath` elements
* specifying which fields to merge. Fields can contain dots to reference nested fields within
* the document. If your input sets any field to an empty dictionary, any nested field is
* overwritten.
* @param completion A block to execute once the document has been successfully written to the
* server. This block will not be called while the client is offline, though local
* changes will be visible immediately.
*/
- (void)setData:(NSDictionary<NSString *, id> *)documentData
mergeFields:(NSArray<id> *)mergeFields
completion:(nullable void (^)(NSError *_Nullable error))completion;
/**
* Updates fields in the document referred to by this `DocumentReference`.
* If the document does not exist, the update fails (specify a completion block to be notified).
*
* @param fields A `Dictionary` containing the fields (expressed as an `String` or
* `FieldPath`) and values with which to update the document.
*/
- (void)updateData:(NSDictionary<id, id> *)fields;
/**
* Updates fields in the document referred to by this `DocumentReference`. If the document
* does not exist, the update fails and the specified completion block receives an error.
*
* @param fields A `Dictionary` containing the fields (expressed as a `String` or
* `FieldPath`) and values with which to update the document.
* @param completion A block to execute when the update is complete. If the update is successful the
* error parameter will be nil, otherwise it will give an indication of how the update failed.
* This block will only execute when the client is online and the commit has completed against
* the server. The completion handler will not be called when the device is offline, though
* local changes will be visible immediately.
*/
- (void)updateData:(NSDictionary<id, id> *)fields
completion:(nullable void (^)(NSError *_Nullable error))completion;
// NOTE: this method is named 'deleteDocument' in Objective-C because 'delete' is a keyword in
// Objective-C++.
/** Deletes the document referred to by this `DocumentReference`. */
// clang-format off
- (void)deleteDocument NS_SWIFT_NAME(delete());
// clang-format on
/**
* Deletes the document referred to by this `DocumentReference`.
*
* @param completion A block to execute once the document has been successfully written to the
* server. This block will not be called while the client is offline, though local
* changes will be visible immediately.
*/
// clang-format off
- (void)deleteDocumentWithCompletion:(nullable void (^)(NSError *_Nullable error))completion
NS_SWIFT_NAME(delete(completion:));
// clang-format on
#pragma mark - Retrieving Data
/**
* Reads the document referenced by this `DocumentReference`.
*
* This method attempts to provide up-to-date data when possible by waiting for
* data from the server, but it may return cached data or fail if you are
* offline and the server cannot be reached. See the
* `getDocument(source:completion:)` method to change this behavior.
*
* @param completion a block to execute once the document has been successfully read.
*/
- (void)getDocumentWithCompletion:
(void (^)(FIRDocumentSnapshot *_Nullable snapshot, NSError *_Nullable error))completion
NS_SWIFT_NAME(getDocument(completion:));
/**
* Reads the document referenced by this `DocumentReference`.
*
* @param source indicates whether the results should be fetched from the cache
* only (`Source.cache`), the server only (`Source.server`), or to attempt
* the server and fall back to the cache (`Source.default`).
* @param completion a block to execute once the document has been successfully read.
*/
// clang-format off
- (void)getDocumentWithSource:(FIRFirestoreSource)source
completion:(void (^)(FIRDocumentSnapshot *_Nullable snapshot,
NSError *_Nullable error))completion
NS_SWIFT_NAME(getDocument(source:completion:));
// clang-format on
/**
* Attaches a listener for `DocumentSnapshot` events.
*
* @param listener The listener to attach.
*
* @return A `ListenerRegistration` that can be used to remove this listener.
*/
- (id<FIRListenerRegistration>)addSnapshotListener:
(void (^)(FIRDocumentSnapshot *_Nullable snapshot, NSError *_Nullable error))listener
NS_SWIFT_NAME(addSnapshotListener(_:));
/**
* Attaches a listener for `DocumentSnapshot` events.
*
* @param includeMetadataChanges Whether metadata-only changes (i.e. only
* `DocumentSnapshot.metadata` changed) should trigger snapshot events.
* @param listener The listener to attach.
*
* @return A `ListenerRegistration` that can be used to remove this listener.
*/
// clang-format off
- (id<FIRListenerRegistration>)
addSnapshotListenerWithIncludeMetadataChanges:(BOOL)includeMetadataChanges
listener:(void (^)(FIRDocumentSnapshot *_Nullable snapshot,
NSError *_Nullable error))listener
NS_SWIFT_NAME(addSnapshotListener(includeMetadataChanges:listener:));
// clang-format on
/**
* Attaches a listener for `DocumentSnapshot` events.
*
* @param options Sets snapshot listener options, including whether metadata-only changes should
* trigger snapshot events, the source to listen to, the executor to use to call the
* listener, or the activity to scope the listener to.
* @param listener The listener to attach.
*
* @return A `ListenerRegistration` that can be used to remove this listener.
*/
- (id<FIRListenerRegistration>)
addSnapshotListenerWithOptions:(FIRSnapshotListenOptions *)options
listener:(void (^)(FIRDocumentSnapshot *_Nullable snapshot,
NSError *_Nullable error))listener
NS_SWIFT_NAME(addSnapshotListener(options:listener:));
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,180 @@
/*
* 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 <Foundation/Foundation.h>
@class FIRDocumentReference;
@class FIRSnapshotMetadata;
NS_ASSUME_NONNULL_BEGIN
/**
* Controls the return value for server timestamps that have not yet been set to
* their final value.
*/
typedef NS_ENUM(NSInteger, FIRServerTimestampBehavior) {
/**
* Return `NSNull` for `FieldValue.serverTimestamp()` fields that have not yet
* been set to their final value.
*/
FIRServerTimestampBehaviorNone,
/**
* Return a local estimates for `FieldValue.serverTimestamp()`
* fields that have not yet been set to their final value. This estimate will
* likely differ from the final value and may cause these pending values to
* change once the server result becomes available.
*/
FIRServerTimestampBehaviorEstimate,
/**
* Return the previous value for `FieldValue.serverTimestamp()` fields that
* have not yet been set to their final value.
*/
FIRServerTimestampBehaviorPrevious
} NS_SWIFT_NAME(ServerTimestampBehavior);
/**
* A `DocumentSnapshot` contains data read from a document in your Firestore database. The data
* can be extracted with the `data` property or by using subscript syntax to access a specific
* field.
*
* For a `DocumentSnapshot` that points to a non-existing document, any data access will return
* `nil`. You can use the `exists` property to explicitly verify a documents existence.
*/
NS_SWIFT_NAME(DocumentSnapshot)
@interface FIRDocumentSnapshot : NSObject
/** :nodoc: */
- (instancetype)init
__attribute__((unavailable("FIRDocumentSnapshot cannot be created directly.")));
/** True if the document exists. */
@property(nonatomic, assign, readonly) BOOL exists;
/** A `DocumentReference` to the document location. */
@property(nonatomic, strong, readonly) FIRDocumentReference *reference;
/** The ID of the document for which this `DocumentSnapshot` contains data. */
@property(nonatomic, copy, readonly) NSString *documentID;
/** Metadata about this snapshot concerning its source and if it has local modifications. */
@property(nonatomic, strong, readonly) FIRSnapshotMetadata *metadata;
/**
* Retrieves all fields in the document as a `Dictionary`. Returns `nil` if the document doesn't
* exist.
*
* Server-provided timestamps that have not yet been set to their final value will be returned as
* `NSNull`. You can use the `data(with:)` method to configure this behavior.
*
* @return A `Dictionary` containing all fields in the document or `nil` if the document doesn't
* exist.
*/
- (nullable NSDictionary<NSString *, id> *)data;
/**
* Retrieves all fields in the document as a `Dictionary`. Returns `nil` if the document doesn't
* exist.
*
* @param serverTimestampBehavior Configures how server timestamps that have not yet been set to
* their final value are returned from the snapshot.
* @return A `Dictionary` containing all fields in the document or `nil` if the document doesn't
* exist.
*/
- (nullable NSDictionary<NSString *, id> *)dataWithServerTimestampBehavior:
(FIRServerTimestampBehavior)serverTimestampBehavior;
/**
* Retrieves a specific field from the document. Returns `nil` if the document or the field doesn't
* exist.
*
* The timestamps that have not yet been set to their final value will be returned as `NSNull`. You
* can use `get(_:serverTimestampBehavior:)` to configure this behavior.
*
* @param field The field to retrieve.
* @return The value contained in the field or `nil` if the document or field doesn't exist.
*/
- (nullable id)valueForField:(id)field NS_SWIFT_NAME(get(_:));
/**
* Retrieves a specific field from the document. Returns `nil` if the document or the field doesn't
* exist.
*
* The timestamps that have not yet been set to their final value will be returned as `NSNull`. You
* can use `get(_:serverTimestampBehavior:)` to configure this behavior.
*
* @param field The field to retrieve.
* @param serverTimestampBehavior Configures how server timestamps that have not yet been set to
* their final value are returned from the snapshot.
* @return The value contained in the field or `nil` if the document or field doesn't exist.
*/
// clang-format off
- (nullable id)valueForField:(id)field
serverTimestampBehavior:(FIRServerTimestampBehavior)serverTimestampBehavior
NS_SWIFT_NAME(get(_:serverTimestampBehavior:));
// clang-format on
/**
* Retrieves a specific field from the document.
*
* @param key The field to retrieve.
*
* @return The value contained in the field or `nil` if the document or field doesn't exist.
*/
- (nullable id)objectForKeyedSubscript:(id)key;
@end
/**
* A `QueryDocumentSnapshot` contains data read from a document in your Firestore database as
* part of a query. The document is guaranteed to exist and its data can be extracted with the
* `data` property or by using subscript syntax to access a specific field.
*
* A `QueryDocumentSnapshot` offers the same API surface as a `DocumentSnapshot`. As
* deleted documents are not returned from queries, its `exists` property will always be true and
* `data()` will never return `nil`.
*/
NS_SWIFT_NAME(QueryDocumentSnapshot)
@interface FIRQueryDocumentSnapshot : FIRDocumentSnapshot
/** :nodoc: */
- (instancetype)init
__attribute__((unavailable("FIRQueryDocumentSnapshot cannot be created directly.")));
/**
* Retrieves all fields in the document as a `Dictionary`.
*
* Server-provided timestamps that have not yet been set to their final value will be returned as
* `NSNull`. You can use the `data(with:)` method to configure this behavior.
*
* @return A `Dictionary` containing all fields in the document.
*/
- (NSDictionary<NSString *, id> *)data;
/**
* Retrieves all fields in the document as a `Dictionary`.
*
* @param serverTimestampBehavior Configures how server timestamps that have not yet been set to
* their final value are returned from the snapshot.
* @return A `Dictionary` containing all fields in the document.
*/
- (NSDictionary<NSString *, id> *)dataWithServerTimestampBehavior:
(FIRServerTimestampBehavior)serverTimestampBehavior;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,49 @@
/*
* 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 <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
/**
* A `FieldPath` refers to a field in a document. The path may consist of a single field name
* (referring to a top level field in the document), or a list of field names (referring to a nested
* field in the document).
*/
NS_SWIFT_NAME(FieldPath)
@interface FIRFieldPath : NSObject <NSCopying>
/** :nodoc: */
- (instancetype)init NS_UNAVAILABLE;
/**
* Creates a `FieldPath` from the provided field names. If more than one field name is provided, the
* path will point to a nested field in a document.
*
* @param fieldNames A list of field names.
* @return A `FieldPath` that points to a field location in a document.
*/
- (instancetype)initWithFields:(NSArray<NSString *> *)fieldNames NS_SWIFT_NAME(init(_:));
/**
* A special sentinel `FieldPath` to refer to the ID of a document. It can be used in queries to
* sort or filter by the document ID.
*/
+ (instancetype)documentID;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,95 @@
/*
* 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 <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
/**
* Sentinel values that can be used when writing document fields with `setData()` or `updateData()`.
*/
NS_SWIFT_NAME(FieldValue)
@interface FIRFieldValue : NSObject
/** :nodoc: */
- (instancetype)init NS_UNAVAILABLE;
/** Used with `updateData()` to mark a field for deletion. */
// clang-format off
+ (instancetype)fieldValueForDelete NS_SWIFT_NAME(delete());
// clang-format on
/**
* Used with `setData()` or `updateData()` to include a server-generated timestamp in the written
* data.
*/
+ (instancetype)fieldValueForServerTimestamp NS_SWIFT_NAME(serverTimestamp());
/**
* Returns a special value that can be used with `setData()` or `updateData()` that tells the server
* to union the given elements with any array value that already exists on the server. Each
* specified element that doesn't already exist in the array will be added to the end. If the
* field being modified is not already an array it will be overwritten with an array containing
* exactly the specified elements.
*
* @param elements The elements to union into the array.
* @return The `FieldValue` sentinel for use in a call to `setData()` or `updateData()`.
*/
+ (instancetype)fieldValueForArrayUnion:(NSArray<id> *)elements NS_SWIFT_NAME(arrayUnion(_:));
/**
* Returns a special value that can be used with `setData()` or `updateData()` that tells the server
* to remove the given elements from any array value that already exists on the server. All
* instances of each element specified will be removed from the array. If the field being
* modified is not already an array it will be overwritten with an empty array.
*
* @param elements The elements to remove from the array.
* @return The `FieldValue` sentinel for use in a call to `setData()` or `updateData()`.
*/
+ (instancetype)fieldValueForArrayRemove:(NSArray<id> *)elements NS_SWIFT_NAME(arrayRemove(_:));
/**
* Returns a special value that can be used with `setData()` or `updateData()` that tells the server
* to increment the field's current value by the given value.
*
* If the current value is an integer or a double, both the current and the given value will be
* interpreted as doubles and all arithmetic will follow IEEE 754 semantics. Otherwise, the
* transformation will set the field to the given value.
*
* @param d The double value to increment by.
* @return The `FieldValue` sentinel for use in a call to `setData()` or `updateData()`.
*/
+ (instancetype)fieldValueForDoubleIncrement:(double)d NS_SWIFT_NAME(increment(_:));
/**
* Returns a special value that can be used with `setData()` or `updateData()` that tells the server
* to increment the field's current value by the given value.
*
* If the current field value is an integer, possible integer overflows are resolved to LONG_MAX or
* LONG_MIN. If the current field value is a double, both values will be interpreted as doubles and
* the arithmetic will follow IEEE 754 semantics.
*
* If field is not an integer or double, or if the field does not yet exist, the transformation
* will set the field to the given value.
*
* @param l The integer value to increment by.
* @return The `FieldValue` sentinel for use in a call to `setData()` or `updateData()`.
*/
+ (instancetype)fieldValueForIntegerIncrement:(int64_t)l NS_SWIFT_NAME(increment(_:));
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,261 @@
/*
* Copyright 2022 Google LLC
*
* 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 <Foundation/Foundation.h>
@class FIRFieldPath;
NS_ASSUME_NONNULL_BEGIN
/**
* A Filter represents a restriction on one or more field values and can be used to refine
* the results of a Query.
*/
NS_SWIFT_NAME(Filter)
@interface FIRFilter : NSObject
#pragma mark - Create Filter
/**
* Creates a new filter for checking that the given field is equal to the given value.
*
* @param field The field used for the filter.
* @param value The value used for the filter.
* @return The newly created filter.
*/
+ (FIRFilter *)filterWhereField:(nonnull NSString *)field
isEqualTo:(nonnull id)value NS_SWIFT_NAME(whereField(_:isEqualTo:));
/**
* Creates a new filter for checking that the given field is equal to the given value.
*
* @param path The field path used for the filter.
* @param value The value used for the filter.
* @return The newly created filter.
*/
+ (FIRFilter *)filterWhereFieldPath:(nonnull FIRFieldPath *)path
isEqualTo:(nonnull id)value NS_SWIFT_NAME(whereField(_:isEqualTo:));
/**
* Creates a new filter for checking that the given field is not equal to the given value.
*
* @param field The field used for the filter.
* @param value The value used for the filter.
* @return The newly created filter.
*/
+ (FIRFilter *)filterWhereField:(nonnull NSString *)field
isNotEqualTo:(nonnull id)value NS_SWIFT_NAME(whereField(_:isNotEqualTo:));
/**
* Creates a new filter for checking that the given field is not equal to the given value.
*
* @param path The field path used for the filter.
* @param value The value used for the filter.
* @return The newly created filter.
*/
+ (FIRFilter *)filterWhereFieldPath:(nonnull FIRFieldPath *)path
isNotEqualTo:(nonnull id)value NS_SWIFT_NAME(whereField(_:isNotEqualTo:));
/**
* Creates a new filter for checking that the given field is greater than the given value.
*
* @param field The field used for the filter.
* @param value The value used for the filter.
* @return The newly created filter.
*/
+ (FIRFilter *)filterWhereField:(nonnull NSString *)field
isGreaterThan:(nonnull id)value NS_SWIFT_NAME(whereField(_:isGreaterThan:));
/**
* Creates a new filter for checking that the given field is greater than the given value.
*
* @param path The field path used for the filter.
* @param value The value used for the filter.
* @return The newly created filter.
*/
+ (FIRFilter *)filterWhereFieldPath:(nonnull FIRFieldPath *)path
isGreaterThan:(nonnull id)value NS_SWIFT_NAME(whereField(_:isGreaterThan:));
/**
* Creates a new filter for checking that the given field is greater than or equal to the given
* value.
*
* @param field The field used for the filter.
* @param value The value used for the filter.
* @return The newly created filter.
*/
+ (FIRFilter *)filterWhereField:(nonnull NSString *)field
isGreaterThanOrEqualTo:(nonnull id)value NS_SWIFT_NAME(whereField(_:isGreaterOrEqualTo:));
/**
* Creates a new filter for checking that the given field is greater than or equal to the given
* value.
*
* @param path The field path used for the filter.
* @param value The value used for the filter.
* @return The newly created filter.
*/
+ (FIRFilter *)filterWhereFieldPath:(nonnull FIRFieldPath *)path
isGreaterThanOrEqualTo:(nonnull id)value
NS_SWIFT_NAME(whereField(_:isGreaterOrEqualTo:));
/**
* Creates a new filter for checking that the given field is less than the given value.
*
* @param field The field used for the filter.
* @param value The value used for the filter.
* @return The newly created filter.
*/
+ (FIRFilter *)filterWhereField:(nonnull NSString *)field
isLessThan:(nonnull id)value NS_SWIFT_NAME(whereField(_:isLessThan:));
/**
* Creates a new filter for checking that the given field is less than the given value.
*
* @param path The field path used for the filter.
* @param value The value used for the filter.
* @return The newly created filter.
*/
+ (FIRFilter *)filterWhereFieldPath:(nonnull FIRFieldPath *)path
isLessThan:(nonnull id)value NS_SWIFT_NAME(whereField(_:isLessThan:));
/**
* Creates a new filter for checking that the given field is less than or equal to the given
* value.
*
* @param field The field used for the filter.
* @param value The value used for the filter.
* @return The newly created filter.
*/
+ (FIRFilter *)filterWhereField:(nonnull NSString *)field
isLessThanOrEqualTo:(nonnull id)value NS_SWIFT_NAME(whereField(_:isLessThanOrEqualTo:));
/**
* Creates a new filter for checking that the given field is less than or equal to the given
* value.
*
* @param path The field path used for the filter.
* @param value The value used for the filter.
* @return The newly created filter.
*/
+ (FIRFilter *)filterWhereFieldPath:(nonnull FIRFieldPath *)path
isLessThanOrEqualTo:(nonnull id)value
NS_SWIFT_NAME(whereField(_:isLessThanOrEqualTo:));
/**
* Creates a new filter for checking that the given array field contains the given value.
*
* @param field The field used for the filter.
* @param value The value used for the filter.
* @return The newly created filter.
*/
+ (FIRFilter *)filterWhereField:(nonnull NSString *)field
arrayContains:(nonnull id)value NS_SWIFT_NAME(whereField(_:arrayContains:));
/**
* Creates a new filter for checking that the given array field contains the given value.
*
* @param path The field path used for the filter.
* @param value The value used for the filter.
* @return The newly created filter.
*/
+ (FIRFilter *)filterWhereFieldPath:(nonnull FIRFieldPath *)path
arrayContains:(nonnull id)value NS_SWIFT_NAME(whereField(_:arrayContains:));
/**
* Creates a new filter for checking that the given array field contains any of the given values.
*
* @param field The field used for the filter.
* @param values The list of values used for the filter.
* @return The newly created filter.
*/
+ (FIRFilter *)filterWhereField:(nonnull NSString *)field
arrayContainsAny:(nonnull NSArray<id> *)values
NS_SWIFT_NAME(whereField(_:arrayContainsAny:));
/**
* Creates a new filter for checking that the given array field contains any of the given values.
*
* @param path The field path used for the filter.
* @param values The list of values used for the filter.
* @return The newly created filter.
*/
+ (FIRFilter *)filterWhereFieldPath:(nonnull FIRFieldPath *)path
arrayContainsAny:(nonnull NSArray<id> *)values
NS_SWIFT_NAME(whereField(_:arrayContainsAny:));
/**
* Creates a new filter for checking that the given field equals any of the given values.
*
* @param field The field used for the filter.
* @param values The list of values used for the filter.
* @return The newly created filter.
*/
+ (FIRFilter *)filterWhereField:(nonnull NSString *)field
in:(nonnull NSArray<id> *)values NS_SWIFT_NAME(whereField(_:in:));
/**
* Creates a new filter for checking that the given field equals any of the given values.
*
* @param path The field path used for the filter.
* @param values The list of values used for the filter.
* @return The newly created filter.
*/
+ (FIRFilter *)filterWhereFieldPath:(nonnull FIRFieldPath *)path
in:(nonnull NSArray<id> *)values NS_SWIFT_NAME(whereField(_:in:));
/**
* Creates a new filter for checking that the given field does not equal any of the given values.
*
* @param field The field path used for the filter.
* @param values The list of values used for the filter.
* @return The newly created filter.
*/
+ (FIRFilter *)filterWhereField:(nonnull NSString *)field
notIn:(nonnull NSArray<id> *)values NS_SWIFT_NAME(whereField(_:notIn:));
/**
* Creates a new filter for checking that the given field does not equal any of the given values.
*
* @param path The field path used for the filter.
* @param values The list of values used for the filter.
* @return The newly created filter.
*/
+ (FIRFilter *)filterWhereFieldPath:(nonnull FIRFieldPath *)path
notIn:(nonnull NSArray<id> *)values
NS_SWIFT_NAME(whereField(_:notIn:));
/**
* Creates a new filter that is a disjunction of the given filters. A disjunction filter includes
* a document if it satisfies any of the given filters.
*
* @param filters The list of filters to perform a disjunction for.
* @return The newly created filter.
*/
+ (FIRFilter *)orFilterWithFilters:(NSArray<FIRFilter *> *)filters NS_SWIFT_NAME(orFilter(_:));
/**
* Creates a new filter that is a conjunction of the given filters. A conjunction filter includes
* a document if it satisfies all of the given filters.
*
* @param filters The list of filters to perform a disjunction for.
* @return The newly created filter.
*/
+ (FIRFilter *)andFilterWithFilters:(NSArray<FIRFilter *> *)filters NS_SWIFT_NAME(andFilter(_:));
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,465 @@
/*
* 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 <Foundation/Foundation.h>
#import "FIRListenerRegistration.h"
@class FIRApp;
@class FIRCollectionReference;
@class FIRDocumentReference;
@class FIRFirestoreSettings;
@class FIRLoadBundleTask;
@class FIRLoadBundleTaskProgress;
@class FIRQuery;
@class FIRTransaction;
@class FIRTransactionOptions;
@class FIRWriteBatch;
@class FIRPersistentCacheIndexManager;
NS_ASSUME_NONNULL_BEGIN
/**
* `Firestore` represents a Firestore Database and is the entry point for all Firestore
* operations.
*/
NS_SWIFT_NAME(Firestore)
@interface FIRFirestore : NSObject
#pragma mark - Initializing
/** :nodoc: */
- (instancetype)init __attribute__((unavailable("Use a static constructor method.")));
/**
* Creates, caches, and returns the default `Firestore` using the default `FirebaseApp`. Each
* subsequent invocation returns the same `Firestore` object.
*
* @return The default `Firestore` instance.
*/
+ (instancetype)firestore NS_SWIFT_NAME(firestore());
/**
* Creates, caches, and returns the default `Firestore` object for the specified _app_. Each
* subsequent invocation returns the same `Firestore` object.
*
* @param app The `FirebaseApp` instance to use for authentication and as a source of the Google
* Cloud Project ID for your Firestore Database. If you want the default instance, you should
* explicitly set it to `FirebaseApp.app()`.
*
* @return The default `Firestore` instance.
*/
+ (instancetype)firestoreForApp:(FIRApp *)app NS_SWIFT_NAME(firestore(app:));
/**
* This method is in preview. API signature and functionality are subject to change.
*
* Creates, caches, and returns named `Firestore` object for the specified `FirebaseApp`. Each
* subsequent invocation returns the same `Firestore` object.
*
* @param app The `FirebaseApp` instance to use for authentication and as a source of the Google
* Cloud Project ID for your Firestore Database. If you want the default instance, you should
* explicitly set it to `FirebaseApp.app()`.
* @param database The database name.
*
* @return The named `Firestore` instance.
*/
+ (instancetype)firestoreForApp:(FIRApp *)app
database:(NSString *)database NS_SWIFT_NAME(firestore(app:database:));
/**
* This method is in preview. API signature and functionality are subject to change.
*
* Creates, caches, and returns named `Firestore` object for the default _app_. Each subsequent
* invocation returns the same `Firestore` object.
*
* @param database The database name.
*
* @return The named `Firestore` instance.
*/
+ (instancetype)firestoreForDatabase:(NSString *)database NS_SWIFT_NAME(firestore(database:));
/**
* Custom settings used to configure this `Firestore` object.
*/
@property(nonatomic, copy) FIRFirestoreSettings *settings;
/**
* The Firebase App associated with this Firestore instance.
*/
@property(strong, nonatomic, readonly) FIRApp *app;
#pragma mark - Configure FieldIndexes
/**
* A PersistentCacheIndexManager which you can config persistent cache indexes used for
* local query execution.
*/
@property(nonatomic, readonly, nullable)
FIRPersistentCacheIndexManager *persistentCacheIndexManager;
/**
* NOTE: This preview method will be deprecated in a future major release. Consider using
* `PersistentCacheIndexManager.enableIndexAutoCreation()` to let the SDK decide whether to create
* cache indexes for queries running locally.
*
* Configures indexing for local query execution. Any previous index configuration is overridden.
*
* The index entries themselves are created asynchronously. You can continue to use queries
* that require indexing even if the indices are not yet available. Query execution will
* automatically start using the index once the index entries have been written.
*
* The method accepts the JSON format exported by the Firebase CLI (`firebase
* firestore:indexes`). If the JSON format is invalid, the completion block will be
* invoked with an NSError.
*
* @param json The JSON format exported by the Firebase CLI.
* @param completion A block to execute when setting is in a final state. The `error` parameter
* will be set if the block is invoked due to an error.
*/
- (void)setIndexConfigurationFromJSON:(NSString *)json
completion:(nullable void (^)(NSError *_Nullable error))completion
NS_SWIFT_NAME(setIndexConfiguration(_:completion:)) DEPRECATED_MSG_ATTRIBUTE(
"Instead of creating cache indexes manually, consider using "
"`PersistentCacheIndexManager.enableIndexAutoCreation()` to let the SDK decide whether to "
"create cache indexes for queries running locally.");
/**
* NOTE: This preview method will be deprecated in a future major release. Consider using
* `PersistentCacheIndexManager.enableIndexAutoCreation()` to let the SDK decide whether to create
* cache indexes for queries running locally.
*
* Configures indexing for local query execution. Any previous index configuration is overridden.
*
* The index entries themselves are created asynchronously. You can continue to use queries
* that require indexing even if the indices are not yet available. Query execution will
* automatically start using the index once the index entries have been written.
*
* Indexes are only supported with LevelDB persistence. Invoke `set_persistence_enabled(true)`
* before setting an index configuration. If LevelDB is not enabled, any index configuration
* will be rejected.
*
* The method accepts the JSON format exported by the Firebase CLI (`firebase
* firestore:indexes`). If the JSON format is invalid, this method ignores the changes.
*
* @param stream An input stream from which the configuration can be read.
* @param completion A block to execute when setting is in a final state. The `error` parameter
* will be set if the block is invoked due to an error.
*/
- (void)setIndexConfigurationFromStream:(NSInputStream *)stream
completion:(nullable void (^)(NSError *_Nullable error))completion
NS_SWIFT_NAME(setIndexConfiguration(_:completion:)) DEPRECATED_MSG_ATTRIBUTE(
"Instead of creating cache indexes manually, consider using "
"`PersistentCacheIndexManager.enableIndexAutoCreation()` to let the SDK decide whether to "
"create cache indexes for queries running locally.");
#pragma mark - Collections and Documents
/**
* Gets a `CollectionReference` referring to the collection at the specified path within the
* database.
*
* @param collectionPath The slash-separated path of the collection for which to get a
* `CollectionReference`.
*
* @return The `CollectionReference` at the specified _collectionPath_.
*/
- (FIRCollectionReference *)collectionWithPath:(NSString *)collectionPath
NS_SWIFT_NAME(collection(_:));
/**
* Gets a `DocumentReference` referring to the document at the specified path within the
* database.
*
* @param documentPath The slash-separated path of the document for which to get a
* `DocumentReference`.
*
* @return The `DocumentReference` for the specified _documentPath_.
*/
- (FIRDocumentReference *)documentWithPath:(NSString *)documentPath NS_SWIFT_NAME(document(_:));
#pragma mark - Collection Group Queries
/**
* Creates and returns a new `Query` that includes all documents in the database that are contained
* in a collection or subcollection with the given collectionID.
*
* @param collectionID Identifies the collections to query over. Every collection or subcollection
* with this ID as the last segment of its path will be included. Cannot contain a slash.
* @return The created `Query`.
*/
- (FIRQuery *)collectionGroupWithID:(NSString *)collectionID NS_SWIFT_NAME(collectionGroup(_:));
#pragma mark - Transactions and Write Batches
/**
* Executes the given updateBlock and then attempts to commit the changes applied within an atomic
* transaction.
*
* The maximum number of writes allowed in a single transaction is 500, but note that each usage of
* `FieldValue.serverTimestamp()`, `FieldValue.arrayUnion()`, `FieldValue.arrayRemove()`, or
* `FieldValue.increment()` inside a transaction counts as an additional write.
*
* In the updateBlock, a set of reads and writes can be performed atomically using the
* `Transaction` object passed to the block. After the updateBlock is run, Firestore will attempt
* to apply the changes to the server. If any of the data read has been modified outside of this
* transaction since being read, then the transaction will be retried by executing the updateBlock
* again. If the transaction still fails after 5 retries, then the transaction will fail.
*
* Since the updateBlock may be executed multiple times, it should avoiding doing anything that
* would cause side effects.
*
* Any value maybe be returned from the updateBlock. If the transaction is successfully committed,
* then the completion block will be passed that value. The updateBlock also has an `NSErrorPointer`
* out parameter. If this is set, then the transaction will not attempt to commit, and the given
* error will be passed to the completion block.
*
* The `Transaction` object passed to the updateBlock contains methods for accessing documents
* and collections. Unlike other firestore access, data accessed with the transaction will not
* reflect local changes that have not been committed. For this reason, it is required that all
* reads are performed before any writes. Transactions must be performed while online. Otherwise,
* reads will fail, the final commit will fail, and the completion block will return an error.
*
* @param updateBlock The block to execute within the transaction context.
* @param completion The block to call with the result or error of the transaction. This
* block will run even if the client is offline, unless the process is killed.
*/
- (void)runTransactionWithBlock:(id _Nullable (^)(FIRTransaction *, NSError **))updateBlock
completion:(void (^)(id _Nullable result, NSError *_Nullable error))completion
__attribute__((swift_async(none))); // Disable async import due to #9426.
/**
* Executes the given updateBlock and then attempts to commit the changes applied within an atomic
* transaction.
*
* The maximum number of writes allowed in a single transaction is 500, but note that each usage of
* `FieldValue.serverTimestamp()`, `FieldValue.arrayUnion()`, `FieldValue.arrayRemove()`, or
* `FieldValue.increment()` inside a transaction counts as an additional write.
*
* In the updateBlock, a set of reads and writes can be performed atomically using the
* `Transaction` object passed to the block. After the updateBlock is run, Firestore will attempt
* to apply the changes to the server. If any of the data read has been modified outside of this
* transaction since being read, then the transaction will be retried by executing the updateBlock
* again. If the transaction still fails after the attempting the number of times specified by the
* `max_attempts` property of the given `TransactionOptions` object, then the transaction will fail.
* If the given `TransactionOptions` is `nil`, then the default `max_attempts` of 5 will be used.
*
* Since the updateBlock may be executed multiple times, it should avoiding doing anything that
* would cause side effects.
*
* Any value maybe be returned from the updateBlock. If the transaction is successfully committed,
* then the completion block will be passed that value. The updateBlock also has an `NSErrorPointer`
* out parameter. If this is set, then the transaction will not attempt to commit, and the given
* error will be passed to the completion block.
*
* The `Transaction` object passed to the updateBlock contains methods for accessing documents
* and collections. Unlike other firestore access, data accessed with the transaction will not
* reflect local changes that have not been committed. For this reason, it is required that all
* reads are performed before any writes. Transactions must be performed while online. Otherwise,
* reads will fail, the final commit will fail, and the completion block will return an error.
*
* @param options The transaction options for controlling execution, or `nil` to use the default
* transaction options.
* @param updateBlock The block to execute within the transaction context.
* @param completion The block to call with the result or error of the transaction. This
* block will run even if the client is offline, unless the process is killed.
*/
- (void)runTransactionWithOptions:(FIRTransactionOptions *_Nullable)options
block:(id _Nullable (^)(FIRTransaction *, NSError **))updateBlock
completion:
(void (^)(id _Nullable result, NSError *_Nullable error))completion
__attribute__((swift_async(none))); // Disable async import due to #9426.
/**
* Creates a write batch, used for performing multiple writes as a single
* atomic operation.
*
* The maximum number of writes allowed in a single batch is 500, but note that each usage of
* `FieldValue.serverTimestamp()`, `FieldValue.arrayUnion()`, `FieldValue.arrayRemove()`, or
* `FieldValue.increment()` inside a batch counts as an additional write.
* Unlike transactions, write batches are persisted offline and therefore are preferable when you
* don't need to condition your writes on read data.
*/
- (FIRWriteBatch *)batch;
#pragma mark - Logging
/** Enables or disables logging from the Firestore client. */
+ (void)enableLogging:(BOOL)logging;
#pragma mark - Network
/**
* Configures Firestore to connect to an emulated host instead of the default remote backend. After
* Firestore has been used (i.e. a document reference has been instantiated), this value cannot be
* changed.
*/
- (void)useEmulatorWithHost:(NSString *)host port:(NSInteger)port;
/**
* Re-enables usage of the network by this Firestore instance after a prior call to
* `disableNetwork(completion:)`. Completion block, if provided, will be called once network uasge
* has been enabled.
*/
- (void)enableNetworkWithCompletion:(nullable void (^)(NSError *_Nullable error))completion;
/**
* Disables usage of the network by this Firestore instance. It can be re-enabled by via
* `enableNetwork`. While the network is disabled, any snapshot listeners or get calls will return
* results from cache and any write operations will be queued until the network is restored. The
* completion block, if provided, will be called once network usage has been disabled.
*/
- (void)disableNetworkWithCompletion:(nullable void (^)(NSError *_Nullable error))completion;
/**
* Clears the persistent storage. This includes pending writes and cached documents.
*
* Must be called while the firestore instance is not started (after the app is shutdown or when
* the app is first initialized). On startup, this method must be called before other methods
* (other than `Firestore.settings`). If the firestore instance is still running, the function
* will complete with an error code of `FailedPrecondition`.
*
* Note: `clearPersistence(completion:)` is primarily intended to help write reliable tests that
* use Firestore. It uses the most efficient mechanism possible for dropping existing data but
* does not attempt to securely overwrite or otherwise make cached data unrecoverable. For
* applications that are sensitive to the disclosure of cache data in between user sessions we
* strongly recommend not to enable persistence in the first place.
*/
- (void)clearPersistenceWithCompletion:(nullable void (^)(NSError *_Nullable error))completion;
/**
* Waits until all currently pending writes for the active user have been acknowledged by the
* backend.
*
* The completion block is called immediately without error if there are no outstanding writes.
* Otherwise, the completion block is called when all previously issued writes (including those
* written in a previous app session) have been acknowledged by the backend. The completion
* block does not wait for writes that were added after the method is called. If you
* wish to wait for additional writes, you have to call `waitForPendingWrites` again.
*
* Any outstanding `waitForPendingWrites(completion:)` completion blocks are called with an error
* during user change.
*/
- (void)waitForPendingWritesWithCompletion:(void (^)(NSError *_Nullable error))completion;
/**
* Attaches a listener for a snapshots-in-sync event. The snapshots-in-sync event indicates that all
* listeners affected by a given change have fired, even if a single server-generated change affects
* multiple listeners.
*
* NOTE: The snapshots-in-sync event only indicates that listeners are in sync with each other, but
* does not relate to whether those snapshots are in sync with the server. Use SnapshotMetadata in
* the individual listeners to determine if a snapshot is from the cache or the server.
*
* @param listener A callback to be called every time all snapshot listeners are in sync with each
* other.
* @return A `ListenerRegistration` object that can be used to remove the listener.
*/
- (id<FIRListenerRegistration>)addSnapshotsInSyncListener:(void (^)(void))listener
NS_SWIFT_NAME(addSnapshotsInSyncListener(_:));
#pragma mark - Terminating
/**
* Terminates this `Firestore` instance.
*
* After calling `terminate` only the `clearPersistence` method may be used. Any other method will
* throw an error.
*
* To restart after termination, simply create a new instance of `Firestore` with the `firestore`
* method.
*
* Termination does not cancel any pending writes and any tasks that are awaiting a response from
* the server will not be resolved. The next time you start this instance, it will resume attempting
* to send these writes to the server.
*
* Note: Under normal circumstances, calling this method is not required. This method is useful only
* when you want to force this instance to release all of its resources or in combination with
* `clearPersistence` to ensure that all local state is destroyed between test runs.
*
* @param completion A block to execute once everything has been terminated.
*/
- (void)terminateWithCompletion:(nullable void (^)(NSError *_Nullable error))completion
NS_SWIFT_NAME(terminate(completion:));
#pragma mark - Bundles
/**
* Loads a Firestore bundle into the local cache.
*
* @param bundleData Data from the bundle to be loaded.
* @return A `LoadBundleTask` which allows registered observers
* to receive progress updates and completion or error events.
*/
- (FIRLoadBundleTask *)loadBundle:(NSData *)bundleData NS_SWIFT_NAME(loadBundle(_:));
/**
* Loads a Firestore bundle into the local cache.
*
* @param bundleData Data from the bundle to be loaded.
* @param completion A block to execute when loading is in a final state. The `error` parameter
* will be set if the block is invoked due to an error. If observers are registered to the
* `LoadBundleTask`, this block will be called after all observers are notified.
* @return A `LoadBundleTask` which allows registered observers to receive progress updates and
* completion or error events.
*/
- (FIRLoadBundleTask *)loadBundle:(NSData *)bundleData
completion:(nullable void (^)(FIRLoadBundleTaskProgress *_Nullable progress,
NSError *_Nullable error))completion
NS_SWIFT_NAME(loadBundle(_:completion:));
/**
* Loads a Firestore bundle into the local cache.
*
* @param bundleStream An input stream from which the bundle can be read.
* @return A `LoadBundleTask` which allows registered observers to receive progress updates and
* completion or error events.
*/
- (FIRLoadBundleTask *)loadBundleStream:(NSInputStream *)bundleStream NS_SWIFT_NAME(loadBundle(_:));
/**
* Loads a Firestore bundle into the local cache.
*
* @param bundleStream An input stream from which the bundle can be read.
* @param completion A block to execute when the loading is in a final state. The `error` parameter
* of the block will be set if it is due to an error. If observers are registered to the returning
* `LoadBundleTask`, this block will be called after all observers are notified.
* @return A `LoadBundleTask` which allow registering observers to receive progress updates, and
* completion or error events.
*/
- (FIRLoadBundleTask *)loadBundleStream:(NSInputStream *)bundleStream
completion:
(nullable void (^)(FIRLoadBundleTaskProgress *_Nullable progress,
NSError *_Nullable error))completion
NS_SWIFT_NAME(loadBundle(_:completion:));
/**
* Reads a `Query` from the local cache, identified by the given name.
*
* Named queries are packaged into bundles on the server side (along with the resulting documents)
* and loaded into local cache using `loadBundle`. Once in the local cache, you can use this method
* to extract a query by name.
*
* @param completion A block to execute with the query read from the local cache. If no query can be
* found, its parameter will be `nil`.
*/
- (void)getQueryNamed:(NSString *)name
completion:(void (^)(FIRQuery *_Nullable query))completion
NS_SWIFT_NAME(getQuery(named:completion:));
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,103 @@
/*
* 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 <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
/** The Cloud Firestore error domain. */
FOUNDATION_EXPORT NSString *const FIRFirestoreErrorDomain NS_SWIFT_NAME(FirestoreErrorDomain);
/** Error codes used by Cloud Firestore. */
typedef NS_ERROR_ENUM(FIRFirestoreErrorDomain, FIRFirestoreErrorCode){
/**
* The operation completed successfully. `NSError` objects will never have a code with this
* value.
*/
FIRFirestoreErrorCodeOK = 0,
/** The operation was cancelled (typically by the caller). */
FIRFirestoreErrorCodeCancelled = 1,
/** Unknown error or an error from a different error domain. */
FIRFirestoreErrorCodeUnknown = 2,
/**
* Client specified an invalid argument. Note that this differs from FailedPrecondition.
* InvalidArgument indicates arguments that are problematic regardless of the state of the
* system (e.g., an invalid field name).
*/
FIRFirestoreErrorCodeInvalidArgument = 3,
/**
* Deadline expired before operation could complete. For operations that change the state of the
* system, this error may be returned even if the operation has completed successfully. For
* example, a successful response from a server could have been delayed long enough for the
* deadline to expire.
*/
FIRFirestoreErrorCodeDeadlineExceeded = 4,
/** Some requested document was not found. */
FIRFirestoreErrorCodeNotFound = 5,
/** Some document that we attempted to create already exists. */
FIRFirestoreErrorCodeAlreadyExists = 6,
/** The caller does not have permission to execute the specified operation. */
FIRFirestoreErrorCodePermissionDenied = 7,
/**
* Some resource has been exhausted, perhaps a per-user quota, or perhaps the entire file system
* is out of space.
*/
FIRFirestoreErrorCodeResourceExhausted = 8,
/**
* Operation was rejected because the system is not in a state required for the operation's
* execution.
*/
FIRFirestoreErrorCodeFailedPrecondition = 9,
/**
* The operation was aborted, typically due to a concurrency issue like transaction aborts, etc.
*/
FIRFirestoreErrorCodeAborted = 10,
/** Operation was attempted past the valid range. */
FIRFirestoreErrorCodeOutOfRange = 11,
/** Operation is not implemented or not supported/enabled. */
FIRFirestoreErrorCodeUnimplemented = 12,
/**
* Internal errors. Means some invariants expected by underlying system has been broken. If you
* see one of these errors, something is very broken.
*/
FIRFirestoreErrorCodeInternal = 13,
/**
* The service is currently unavailable. This is a most likely a transient condition and may be
* corrected by retrying with a backoff.
*/
FIRFirestoreErrorCodeUnavailable = 14,
/** Unrecoverable data loss or corruption. */
FIRFirestoreErrorCodeDataLoss = 15,
/** The request does not have valid authentication credentials for the operation. */
FIRFirestoreErrorCodeUnauthenticated = 16} NS_SWIFT_NAME(FirestoreErrorCode);
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,86 @@
/*
* Copyright 2017 Google LLC
*
* 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 <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@protocol FIRLocalCacheSettings;
/** Used to set on-disk cache size to unlimited. Garbage collection will not run. */
FOUNDATION_EXTERN const int64_t
kFIRFirestoreCacheSizeUnlimited NS_SWIFT_NAME(FirestoreCacheSizeUnlimited);
/** Settings used to configure a `Firestore` instance. */
NS_SWIFT_NAME(FirestoreSettings)
@interface FIRFirestoreSettings : NSObject <NSCopying>
/**
* Creates and returns an empty `FirestoreSettings` object.
*
* @return The created `FirestoreSettings` object.
*/
- (instancetype)init NS_DESIGNATED_INITIALIZER;
/** The hostname to connect to. */
@property(nonatomic, copy) NSString* host;
/** Whether to use SSL when connecting. */
@property(nonatomic, getter=isSSLEnabled) BOOL sslEnabled;
/**
* A dispatch queue to be used to execute all completion handlers and event handlers. By default,
* the main queue is used.
*/
@property(nonatomic, strong) dispatch_queue_t dispatchQueue;
/**
* NOTE: This field will be deprecated in a future major release. Use the `cacheSettings` field
* instead to specify cache type, and other cache configurations.
*
* Set to false to disable local persistent storage.
*/
@property(nonatomic, getter=isPersistenceEnabled) BOOL persistenceEnabled DEPRECATED_MSG_ATTRIBUTE(
"This field is deprecated. Use `cacheSettings` instead.");
/**
* NOTE: This field will be deprecated in a future major release. Use the `cacheSettings` field
* instead to specify cache size, and other cache configurations.
*
* Sets the cache size threshold above which the SDK will attempt to collect least-recently-used
* documents. The size is not a guarantee that the cache will stay below that size, only that if
* the cache exceeds the given size, cleanup will be attempted. Cannot be set lower than 1MB.
*
* Set to `FirestoreCacheSizeUnlimited` to disable garbage collection entirely.
*/
@property(nonatomic, assign) int64_t cacheSizeBytes DEPRECATED_MSG_ATTRIBUTE(
"This field is deprecated. Use `cacheSettings` instead.");
/**
* Specifies the cache used by the SDK. Available options are `PersistentCacheSettings`
* and `MemoryCacheSettings`, each with different configuration options.
*
* When unspecified, `PersistentCacheSettings` will be used by default.
*
* NOTE: setting this field and `cacheSizeBytes` or `persistenceEnabled` at the same time will throw
* an exception during SDK initialization. Instead, use the configuration in
* the `PersistentCacheSettings` object to specify the cache size.
*/
@property(nonatomic, strong) id<FIRLocalCacheSettings, NSObject> cacheSettings;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,53 @@
/*
* Copyright 2018 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 <Foundation/Foundation.h>
/**
* An enum that configures the behavior of `DocumentReference.getDocument()` and
* `Query.getDocuments()`. By providing a source enum the `getDocument[s]`
* methods can be configured to fetch results only from the server, only from
* the local cache, or attempt to fetch results from the server and fall back to
* the cache (which is the default).
*/
typedef NS_ENUM(NSUInteger, FIRFirestoreSource) {
/**
* Causes Firestore to try to retrieve an up-to-date (server-retrieved)
* snapshot, but fall back to returning cached data if the server can't be
* reached.
*/
FIRFirestoreSourceDefault,
/**
* Causes Firestore to avoid the cache, generating an error if the server
* cannot be reached. Note that the cache will still be updated if the
* server request succeeds. Also note that latency-compensation still takes
* effect, so any pending write operations will be visible in the returned
* data (merged into the server-provided data).
*/
FIRFirestoreSourceServer,
/**
* Causes Firestore to immediately return a value from the cache, ignoring
* the server completely (implying that the returned value may be stale with
* respect to the value on the server). If there is no data in the cache to
* satisfy the `getDocument[s]` call, `DocumentReference.getDocument()` will
* return an error and `QuerySnapshot.getDocuments()` will return an empty
* `QuerySnapshot` with no documents.
*/
FIRFirestoreSourceCache
} NS_SWIFT_NAME(FirestoreSource);

View File

@@ -0,0 +1,54 @@
/*
* 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 <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
/**
* An immutable object representing a geographical point in Firestore. The point is represented as
* a latitude/longitude pair.
*
* Latitude values are in the range of [-90, 90].
* Longitude values are in the range of [-180, 180].
*/
NS_SWIFT_NAME(GeoPoint)
@interface FIRGeoPoint : NSObject <NSCopying>
/** :nodoc: */
- (instancetype)init NS_UNAVAILABLE;
/**
* Creates a `GeoPoint` from the provided latitude and longitude degrees.
* @param latitude The latitude as number between -90 and 90.
* @param longitude The longitude as number between -180 and 180.
*/
- (instancetype)initWithLatitude:(double)latitude
longitude:(double)longitude NS_DESIGNATED_INITIALIZER;
/**
* The point's latitude. Must be a value between -90 and 90 (inclusive).
*/
@property(nonatomic, readonly) double latitude;
/**
* The point's longitude. Must be a value between -180 and 180 (inclusive).
*/
@property(nonatomic, readonly) double longitude;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,33 @@
/*
* 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 <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
/** Represents a listener that can be removed by calling remove. */
NS_SWIFT_NAME(ListenerRegistration)
@protocol FIRListenerRegistration <NSObject>
/**
* Removes the listener being tracked by this `ListenerRegistration`. After the initial call,
* subsequent calls have no effect.
*/
- (void)remove;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,91 @@
/*
* Copyright 2021 Google LLC
*
* 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 <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
/**
* Represents the state of bundle loading tasks.
*
* Both `error` and `inProgress` are final states: the task will be in either an aborted or
* completed state and there will be no more subsequent updates.
*/
typedef NS_ENUM(NSInteger, FIRLoadBundleTaskState) {
FIRLoadBundleTaskStateError,
FIRLoadBundleTaskStateInProgress,
FIRLoadBundleTaskStateSuccess,
} NS_SWIFT_NAME(LoadBundleTaskState);
/** Represents a progress update or a final state from loading bundles. */
NS_SWIFT_NAME(LoadBundleTaskProgress)
@interface FIRLoadBundleTaskProgress : NSObject
/** How many documents have been loaded. */
@property(readonly, nonatomic) NSInteger documentsLoaded;
/** The total number of documents in the bundle. 0 if the bundle failed to parse. */
@property(readonly, nonatomic) NSInteger totalDocuments;
/** How many bytes have been loaded. */
@property(readonly, nonatomic) NSInteger bytesLoaded;
/** The total number of bytes in the bundle. 0 if the bundle failed to parse. */
@property(readonly, nonatomic) NSInteger totalBytes;
/** The current state of `LoadBundleTask`. */
@property(readonly, nonatomic) FIRLoadBundleTaskState state;
@end
/** A handle associated with registered observers that can be used to remove them. */
typedef NSInteger FIRLoadBundleObserverHandle NS_SWIFT_NAME(LoadBundleObserverHandle);
/**
* Represents the task of loading a Firestore bundle. Observers can be registered with this task to
* observe the bundle loading progress, as well as task completion and error events.
*/
NS_SWIFT_NAME(LoadBundleTask)
@interface FIRLoadBundleTask : NSObject
/**
* Registers an observer to observe the progress updates, completion or error events.
*
* @return A handle to the registered observer which can be used to remove the observer once it is
* no longer needed.
*/
- (FIRLoadBundleObserverHandle)addObserver:(void (^)(FIRLoadBundleTaskProgress *progress))observer
NS_SWIFT_NAME(addObserver(_:));
/**
* Removes a registered observer associated with the given handle. If no observer can be found, this
* will be a no-op.
*/
- (void)removeObserverWithHandle:(FIRLoadBundleObserverHandle)handle
NS_SWIFT_NAME(removeObserverWith(handle:));
/**
* Removes all registered observers for this task.
*/
- (void)removeAllObservers NS_SWIFT_NAME(removeAllObservers());
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,142 @@
/*
* Copyright 2023 Google LLC
*
* 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 <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
/**
* Marker protocol implemented by all supported cache settings.
*
* The two cache types supported are `PersistentCacheSettings` and `MemoryCacheSettings`. Custom
* implementation is not supported.
*/
NS_SWIFT_NAME(LocalCacheSettings)
@protocol FIRLocalCacheSettings
@end
/**
* Configures the SDK to use a persistent cache. Firestore documents and mutations are persisted
* across App restart.
*
* This is the default cache type unless explicitly specified otherwise.
*
* To use, create an instance using one of the initializers, then set the instance to
* `FirestoreSettings.cacheSettings`, and use `FirestoreSettings` instance to configure Firestore
* SDK.
*/
NS_SWIFT_NAME(PersistentCacheSettings)
@interface FIRPersistentCacheSettings : NSObject <NSCopying, FIRLocalCacheSettings>
/**
* Creates `PersistentCacheSettings` with default cache size: 100MB.
*
* The cache size is not a hard limit, but a target for the SDK's gabarge collector to work towards.
*/
- (instancetype)init;
/**
* Creates `PersistentCacheSettings` with a custom cache size in bytes.
*
* The cache size is not a hard limit, but a target for the SDK's gabarge collector to work towards.
*/
- (instancetype)initWithSizeBytes:(NSNumber *)size;
@end
/**
* Marker protocol implemented by all supported garbage collector settings.
*
* The two cache types supported are `MemoryEagerGCSettings` and `MemoryLRUGCSettings`. Custom
* implementation is not supported.
*/
NS_SWIFT_NAME(MemoryGarbageCollectorSettings)
@protocol FIRMemoryGarbageCollectorSettings
@end
/**
* Configures the SDK to use an eager garbage collector for memory cache.
*
* Once configured, the SDK will remove any Firestore documents from memory as soon as they are not
* used by any active queries.
*
* To use, create an instance using the initializer, then initialize
* `MemoryCacheSettings` with this instance. This is the default garbage collector, so alternatively
* you can use the default initializer of `MemoryCacheSettings`.
*/
NS_SWIFT_NAME(MemoryEagerGCSetting)
@interface FIRMemoryEagerGCSettings : NSObject <NSCopying, FIRMemoryGarbageCollectorSettings>
/**
* Creates an instance of `MemoryEagerGCSettings`.
*/
- (instancetype)init;
@end
/**
* Configures the SDK to use a least-recently-used garbage collector for memory cache.
*
* Once configured, the SDK will attempt to remove documents that are least recently used in
* batches, if the current cache size is larger than the given target cache size. Default cache size
* is 100MB.
*
* To use, create an instance using one of the initializers, then initialize
* `MemoryCacheSettings` with this instance.
*/
NS_SWIFT_NAME(MemoryLRUGCSettings)
@interface FIRMemoryLRUGCSettings : NSObject <NSCopying, FIRMemoryGarbageCollectorSettings>
/**
* Creates an instance of `FIRMemoryLRUGCSettings`, with default target cache size 100MB. The SDK
* will run garbage collection if the current cache size is larger than 100MB.
*/
- (instancetype)init;
/**
* Creates an instance of `FIRMemoryLRUGCSettings`, with a custom target cache size. The SDK will
* run garbage collection if the current cache size is larger than the given size.
*/
- (instancetype)initWithSizeBytes:(NSNumber *)size;
@end
/**
* Configures the SDK to use a memory cache. Firestore documents and mutations are NOT persisted
* across App restart.
*
* To use, create an instance using one of the initializer, then set the instance to
* `FirestoreSettings.cacheSettings`, and use `FirestoreSettings` instance to configure Firestore
* SDK.
*/
NS_SWIFT_NAME(MemoryCacheSettings)
@interface FIRMemoryCacheSettings : NSObject <NSCopying, FIRLocalCacheSettings>
/**
* Creates an instance of `MemoryCacheSettings`.
*/
- (instancetype)init;
/**
* Creates an instance of `MemoryCacheSettings` with given `MemoryGarbageCollectorSettings` to
* custom the gabarge collector.
*/
- (instancetype)initWithGarbageCollectorSettings:
(id<FIRMemoryGarbageCollectorSettings, NSObject>)settings;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,55 @@
/*
* Copyright 2023 Google LLC
*
* 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 <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
/**
* A PersistentCacheIndexManager, for configuring persistent cache indexes used for local query
* execution.
*/
NS_SWIFT_NAME(PersistentCacheIndexManager)
@interface FIRPersistentCacheIndexManager : NSObject
/** :nodoc: */
- (instancetype)init
__attribute__((unavailable("FIRPersistentCacheIndexManager cannot be created directly.")));
/**
* Enables the SDK to create persistent cache indexes automatically for local query execution when
* the SDK believes cache indexes can improve performance.
*
* This feature is disabled by default.
*/
- (void)enableIndexAutoCreation NS_SWIFT_NAME(enableIndexAutoCreation());
/**
* Stops creating persistent cache indexes automatically for local query execution. The indexes
* which have been created by calling `enableIndexAutoCreation` still take effect.
*/
- (void)disableIndexAutoCreation NS_SWIFT_NAME(disableIndexAutoCreation());
/**
* Removes all persistent cache indexes. Please note this function also deletes indexes generated by
* [[FIRFirestore firestore] setIndexConfigurationFromJSON] and [[FIRFirestore firestore]
* setIndexConfigurationFromStream], which are deprecated.
*/
- (void)deleteAllIndexes NS_SWIFT_NAME(deleteAllIndexes());
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,604 @@
/*
* 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 <Foundation/Foundation.h>
#import "FIRFirestoreSource.h"
#import "FIRListenerRegistration.h"
#import "FIRSnapshotListenOptions.h"
@class FIRAggregateQuery;
@class FIRAggregateField;
@class FIRFieldPath;
@class FIRFirestore;
@class FIRFilter;
@class FIRQuerySnapshot;
@class FIRDocumentSnapshot;
NS_ASSUME_NONNULL_BEGIN
/**
* A block type used to handle failable snapshot method callbacks.
*/
typedef void (^FIRQuerySnapshotBlock)(FIRQuerySnapshot *_Nullable snapshot,
NSError *_Nullable error)
NS_SWIFT_UNAVAILABLE("Use Swift's closure syntax instead.");
/**
* A `Query` refers to a query which you can read or listen to. You can also construct
* refined `Query` objects by adding filters and ordering.
*/
NS_SWIFT_NAME(Query)
@interface FIRQuery : NSObject
/** :nodoc: */
- (id)init __attribute__((unavailable("FIRQuery cannot be created directly.")));
/** The `Firestore` instance that created this query (useful for performing transactions, etc.). */
@property(nonatomic, strong, readonly) FIRFirestore *firestore;
#pragma mark - Retrieving Data
/**
* Reads the documents matching this query.
*
* This method attempts to provide up-to-date data when possible by waiting for
* data from the server, but it may return cached data or fail if you are
* offline and the server cannot be reached. See the
* `getDocuments(source:completion:)` method to change this behavior.
*
* @param completion a block to execute once the documents have been successfully read.
* documentSet will be `nil` only if error is `non-nil`.
*/
- (void)getDocumentsWithCompletion:
(void (^)(FIRQuerySnapshot *_Nullable snapshot, NSError *_Nullable error))completion
NS_SWIFT_NAME(getDocuments(completion:));
/**
* Reads the documents matching this query.
*
* @param source indicates whether the results should be fetched from the cache
* only (`Source.cache`), the server only (`Source.server`), or to attempt
* the server and fall back to the cache (`Source.default`).
* @param completion a block to execute once the documents have been successfully read.
* documentSet will be `nil` only if error is `non-nil`.
*/
- (void)getDocumentsWithSource:(FIRFirestoreSource)source
completion:(void (^)(FIRQuerySnapshot *_Nullable snapshot,
NSError *_Nullable error))completion
NS_SWIFT_NAME(getDocuments(source:completion:));
/**
* Attaches a listener for `QuerySnapshot` events.
*
* @param listener The listener to attach.
*
* @return A `ListenerRegistration` object that can be used to remove this listener.
*/
- (id<FIRListenerRegistration>)addSnapshotListener:
(void (^)(FIRQuerySnapshot *_Nullable snapshot, NSError *_Nullable error))listener
NS_SWIFT_NAME(addSnapshotListener(_:));
/**
* Attaches a listener for `QuerySnapshot` events.
*
* @param includeMetadataChanges Whether metadata-only changes (i.e. only
* `DocumentSnapshot.metadata` changed) should trigger snapshot events.
* @param listener The listener to attach.
*
* @return A `ListenerRegistration` that can be used to remove this listener.
*/
- (id<FIRListenerRegistration>)
addSnapshotListenerWithIncludeMetadataChanges:(BOOL)includeMetadataChanges
listener:(void (^)(FIRQuerySnapshot *_Nullable snapshot,
NSError *_Nullable error))listener
NS_SWIFT_NAME(addSnapshotListener(includeMetadataChanges:listener:));
/**
* Attaches a listener for `QuerySnapshot` events.
* @param options Sets snapshot listener options, including whether metadata-only changes should
* trigger snapshot events, the source to listen to, the executor to use to call the
* listener, or the activity to scope the listener to.
* @param listener The listener to attach.
*
* @return A `ListenerRegistration` that can be used to remove this listener.
*/
- (id<FIRListenerRegistration>)
addSnapshotListenerWithOptions:(FIRSnapshotListenOptions *)options
listener:(void (^)(FIRQuerySnapshot *_Nullable snapshot,
NSError *_Nullable error))listener
NS_SWIFT_NAME(addSnapshotListener(options:listener:));
#pragma mark - Filtering Data
/**
* Creates and returns a new Query with the additional filter.
*
* @param filter The new filter to apply to the existing query.
* @return The newly created Query.
*/
- (FIRQuery *)queryWhereFilter:(FIRFilter *)filter NS_SWIFT_NAME(whereFilter(_:));
/**
* Creates and returns a new `Query` with the additional filter that documents must
* contain the specified field and the value must be equal to the specified value.
*
* @param field The name of the field to compare.
* @param value The value the field must be equal to.
*
* @return The created `Query`.
*/
- (FIRQuery *)queryWhereField:(NSString *)field
isEqualTo:(id)value NS_SWIFT_NAME(whereField(_:isEqualTo:));
/**
* Creates and returns a new `Query` with the additional filter that documents must
* contain the specified field and the value does not equal the specified value.
*
* @param path The path of the field to compare.
* @param value The value the field must be equal to.
*
* @return The created `Query`.
*/
- (FIRQuery *)queryWhereFieldPath:(FIRFieldPath *)path
isNotEqualTo:(id)value NS_SWIFT_NAME(whereField(_:isNotEqualTo:));
/**
* Creates and returns a new `Query` with the additional filter that documents must
* contain the specified field and the value does not equal the specified value.
*
* @param field The name of the field to compare.
* @param value The value the field must be equal to.
*
* @return The created `Query`.
*/
- (FIRQuery *)queryWhereField:(NSString *)field
isNotEqualTo:(id)value NS_SWIFT_NAME(whereField(_:isNotEqualTo:));
/**
* Creates and returns a new `Query` with the additional filter that documents must
* contain the specified field and the value must be equal to the specified value.
*
* @param path The path of the field to compare.
* @param value The value the field must be equal to.
*
* @return The created `Query`.
*/
- (FIRQuery *)queryWhereFieldPath:(FIRFieldPath *)path
isEqualTo:(id)value NS_SWIFT_NAME(whereField(_:isEqualTo:));
/**
* Creates and returns a new `Query` with the additional filter that documents must
* contain the specified field and the value must be less than the specified value.
*
* @param field The name of the field to compare.
* @param value The value the field must be less than.
*
* @return The created `Query`.
*/
- (FIRQuery *)queryWhereField:(NSString *)field
isLessThan:(id)value NS_SWIFT_NAME(whereField(_:isLessThan:));
/**
* Creates and returns a new `Query` with the additional filter that documents must
* contain the specified field and the value must be less than the specified value.
*
* @param path The path of the field to compare.
* @param value The value the field must be less than.
*
* @return The created `Query`.
*/
- (FIRQuery *)queryWhereFieldPath:(FIRFieldPath *)path
isLessThan:(id)value NS_SWIFT_NAME(whereField(_:isLessThan:));
/**
* Creates and returns a new `Query` with the additional filter that documents must
* contain the specified field and the value must be less than or equal to the specified value.
*
* @param field The name of the field to compare
* @param value The value the field must be less than or equal to.
*
* @return The created `Query`.
*/
- (FIRQuery *)queryWhereField:(NSString *)field
isLessThanOrEqualTo:(id)value NS_SWIFT_NAME(whereField(_:isLessThanOrEqualTo:));
/**
* Creates and returns a new `Query` with the additional filter that documents must
* contain the specified field and the value must be less than or equal to the specified value.
*
* @param path The path of the field to compare
* @param value The value the field must be less than or equal to.
*
* @return The created `Query`.
*/
- (FIRQuery *)queryWhereFieldPath:(FIRFieldPath *)path
isLessThanOrEqualTo:(id)value NS_SWIFT_NAME(whereField(_:isLessThanOrEqualTo:));
/**
* Creates and returns a new `Query` with the additional filter that documents must
* contain the specified field and the value must greater than the specified value.
*
* @param field The name of the field to compare
* @param value The value the field must be greater than.
*
* @return The created `Query`.
*/
- (FIRQuery *)queryWhereField:(NSString *)field
isGreaterThan:(id)value NS_SWIFT_NAME(whereField(_:isGreaterThan:));
/**
* Creates and returns a new `Query` with the additional filter that documents must
* contain the specified field and the value must greater than the specified value.
*
* @param path The path of the field to compare
* @param value The value the field must be greater than.
*
* @return The created `Query`.
*/
- (FIRQuery *)queryWhereFieldPath:(FIRFieldPath *)path
isGreaterThan:(id)value NS_SWIFT_NAME(whereField(_:isGreaterThan:));
/**
* Creates and returns a new `Query` with the additional filter that documents must
* contain the specified field and the value must be greater than or equal to the specified value.
*
* @param field The name of the field to compare
* @param value The value the field must be greater than.
*
* @return The created `Query`.
*/
- (FIRQuery *)queryWhereField:(NSString *)field
isGreaterThanOrEqualTo:(id)value NS_SWIFT_NAME(whereField(_:isGreaterThanOrEqualTo:));
/**
* Creates and returns a new `Query` with the additional filter that documents must
* contain the specified field and the value must be greater than or equal to the specified value.
*
* @param path The path of the field to compare
* @param value The value the field must be greater than.
*
* @return The created `Query`.
*/
- (FIRQuery *)queryWhereFieldPath:(FIRFieldPath *)path
isGreaterThanOrEqualTo:(id)value NS_SWIFT_NAME(whereField(_:isGreaterThanOrEqualTo:));
/**
* Creates and returns a new `Query` with the additional filter that documents must contain
* the specified field, it must be an array, and the array must contain the provided value.
*
* A query can have only one `arrayContains` filter.
*
* @param field The name of the field containing an array to search
* @param value The value that must be contained in the array
*
* @return The created `Query`.
*/
- (FIRQuery *)queryWhereField:(NSString *)field
arrayContains:(id)value NS_SWIFT_NAME(whereField(_:arrayContains:));
/**
* Creates and returns a new `Query` with the additional filter that documents must contain
* the specified field, it must be an array, and the array must contain the provided value.
*
* A query can have only one `arrayContains` filter.
*
* @param path The path of the field containing an array to search
* @param value The value that must be contained in the array
*
* @return The created `Query`.
*/
- (FIRQuery *)queryWhereFieldPath:(FIRFieldPath *)path
arrayContains:(id)value NS_SWIFT_NAME(whereField(_:arrayContains:));
/**
* Creates and returns a new `Query` with the additional filter that documents must contain
* the specified field, the value must be an array, and that array must contain at least one value
* from the provided array.
*
* A query can have only one `arrayContainsAny` filter and it cannot be combined with
* `arrayContains` or `in` filters.
*
* @param field The name of the field containing an array to search.
* @param values The array that contains the values to match.
*
* @return The created `Query`.
*/
- (FIRQuery *)queryWhereField:(NSString *)field
arrayContainsAny:(NSArray<id> *)values NS_SWIFT_NAME(whereField(_:arrayContainsAny:));
/**
* Creates and returns a new `Query` with the additional filter that documents must contain
* the specified field, the value must be an array, and that array must contain at least one value
* from the provided array.
*
* A query can have only one `arrayContainsAny` filter and it cannot be combined with
* `arrayContains` or `in` filters.
*
* @param path The path of the field containing an array to search.
* @param values The array that contains the values to match.
*
* @return The created `Query`.
*/
- (FIRQuery *)queryWhereFieldPath:(FIRFieldPath *)path
arrayContainsAny:(NSArray<id> *)values
NS_SWIFT_NAME(whereField(_:arrayContainsAny:));
/**
* Creates and returns a new `Query` with the additional filter that documents must contain
* the specified field and the value must equal one of the values from the provided array.
*
* A query can have only one `in` filter, and it cannot be combined with an `arrayContainsAny`
* filter.
*
* @param field The name of the field to search.
* @param values The array that contains the values to match.
*
* @return The created `Query`.
*/
- (FIRQuery *)queryWhereField:(NSString *)field
in:(NSArray<id> *)values NS_SWIFT_NAME(whereField(_:in:));
/**
* Creates and returns a new `Query` with the additional filter that documents must contain
* the specified field and the value must equal one of the values from the provided array.
*
* A query can have only one `in` filter, and it cannot be combined with an `arrayContainsAny`
* filter.
*
* @param path The path of the field to search.
* @param values The array that contains the values to match.
*
* @return The created `Query`.
*/
- (FIRQuery *)queryWhereFieldPath:(FIRFieldPath *)path
in:(NSArray<id> *)values NS_SWIFT_NAME(whereField(_:in:));
/**
* Creates and returns a new `Query` with the additional filter that documents must contain
* the specified field and the value does not equal any of the values from the provided array.
*
* One special case is that `notIn` filters cannot match `nil` values. To query for documents
* where a field exists and is `nil`, use a `notEqual` filter, which can handle this special case.
*
* A query can have only one `notIn` filter, and it cannot be combined with an `arrayContains`,
* `arrayContainsAny`, `in`, or `notEqual` filter.
*
* @param field The name of the field to search.
* @param values The array that contains the values to match.
*
* @return The created `Query`.
*/
- (FIRQuery *)queryWhereField:(NSString *)field
notIn:(NSArray<id> *)values NS_SWIFT_NAME(whereField(_:notIn:));
/**
* Creates and returns a new `Query` with the additional filter that documents must contain
* the specified field and the value does not equal any of the values from the provided array.
*
* One special case is that `notIn` filters cannot match `nil` values. To query for documents
* where a field exists and is `nil`, use a `notEqual` filter, which can handle this special case.
*
* Passing in a `null` value into the `values` array results in no document matches. To query
* for documents where a field is not `null`, use a `notEqual` filter.
*
* @param path The path of the field to search.
* @param values The array that contains the values to match.
*
* @return The created `Query`.
*/
- (FIRQuery *)queryWhereFieldPath:(FIRFieldPath *)path
notIn:(NSArray<id> *)values NS_SWIFT_NAME(whereField(_:notIn:));
/**
* Creates and returns a new `Query` with the additional filter that documents must
* satisfy the specified predicate.
*
* @param predicate The predicate the document must satisfy. Can be either comparison
* or compound of comparison. In particular, block-based predicate is not supported.
*
* @return The created `Query`.
*/
- (FIRQuery *)queryFilteredUsingPredicate:(NSPredicate *)predicate NS_SWIFT_NAME(filter(using:));
#pragma mark - Sorting Data
/**
* Creates and returns a new `Query` that's additionally sorted by the specified field.
*
* @param field The field to sort by.
*
* @return The created `Query`.
*/
- (FIRQuery *)queryOrderedByField:(NSString *)field NS_SWIFT_NAME(order(by:));
/**
* Creates and returns a new `Query` that's additionally sorted by the specified field.
*
* @param path The field to sort by.
*
* @return The created `Query`.
*/
- (FIRQuery *)queryOrderedByFieldPath:(FIRFieldPath *)path NS_SWIFT_NAME(order(by:));
/**
* Creates and returns a new `Query` that's additionally sorted by the specified field,
* optionally in descending order instead of ascending.
*
* @param field The field to sort by.
* @param descending Whether to sort descending.
*
* @return The created `Query`.
*/
- (FIRQuery *)queryOrderedByField:(NSString *)field
descending:(BOOL)descending NS_SWIFT_NAME(order(by:descending:));
/**
* Creates and returns a new `Query` that's additionally sorted by the specified field,
* optionally in descending order instead of ascending.
*
* @param path The field to sort by.
* @param descending Whether to sort descending.
*
* @return The created `Query`.
*/
- (FIRQuery *)queryOrderedByFieldPath:(FIRFieldPath *)path
descending:(BOOL)descending NS_SWIFT_NAME(order(by:descending:));
#pragma mark - Limiting Data
/**
* Creates and returns a new `Query` that only returns the first matching documents up to
* the specified number.
*
* @param limit The maximum number of items to return.
*
* @return The created `Query`.
*/
- (FIRQuery *)queryLimitedTo:(NSInteger)limit NS_SWIFT_NAME(limit(to:));
/**
* Creates and returns a new `Query` that only returns the last matching documents up to
* the specified number.
*
* A query with a `limit(toLast:)` clause must have at least one `orderBy` clause.
*
* @param limit The maximum number of items to return.
*
* @return The created `Query`.
*/
- (FIRQuery *)queryLimitedToLast:(NSInteger)limit NS_SWIFT_NAME(limit(toLast:));
#pragma mark - Choosing Endpoints
/**
* Creates and returns a new `Query` that starts at the provided document (inclusive). The
* starting position is relative to the order of the query. The document must contain all of the
* fields provided in the orderBy of this query.
*
* @param document The snapshot of the document to start at.
*
* @return The created `Query`.
*/
- (FIRQuery *)queryStartingAtDocument:(FIRDocumentSnapshot *)document
NS_SWIFT_NAME(start(atDocument:));
/**
* Creates and returns a new `Query` that starts at the provided fields relative to the order of
* the query. The order of the field values must match the order of the order by clauses of the
* query.
*
* @param fieldValues The field values to start this query at, in order of the query's order by.
*
* @return The created `Query`.
*/
- (FIRQuery *)queryStartingAtValues:(NSArray *)fieldValues NS_SWIFT_NAME(start(at:));
/**
* Creates and returns a new `Query` that starts after the provided document (exclusive). The
* starting position is relative to the order of the query. The document must contain all of the
* fields provided in the orderBy of this query.
*
* @param document The snapshot of the document to start after.
*
* @return The created `Query`.
*/
- (FIRQuery *)queryStartingAfterDocument:(FIRDocumentSnapshot *)document
NS_SWIFT_NAME(start(afterDocument:));
/**
* Creates and returns a new `Query` that starts after the provided fields relative to the order
* of the query. The order of the field values must match the order of the order by clauses of the
* query.
*
* @param fieldValues The field values to start this query after, in order of the query's orderBy.
*
* @return The created `Query`.
*/
- (FIRQuery *)queryStartingAfterValues:(NSArray *)fieldValues NS_SWIFT_NAME(start(after:));
/**
* Creates and returns a new `Query` that ends before the provided document (exclusive). The end
* position is relative to the order of the query. The document must contain all of the fields
* provided in the orderBy of this query.
*
* @param document The snapshot of the document to end before.
*
* @return The created `Query`.
*/
- (FIRQuery *)queryEndingBeforeDocument:(FIRDocumentSnapshot *)document
NS_SWIFT_NAME(end(beforeDocument:));
/**
* Creates and returns a new `Query` that ends before the provided fields relative to the order
* of the query. The order of the field values must match the order of the order by clauses of the
* query.
*
* @param fieldValues The field values to end this query before, in order of the query's order by.
*
* @return The created `Query`.
*/
- (FIRQuery *)queryEndingBeforeValues:(NSArray *)fieldValues NS_SWIFT_NAME(end(before:));
/**
* Creates and returns a new `Query` that ends at the provided document (exclusive). The end
* position is relative to the order of the query. The document must contain all of the fields
* provided in the orderBy of this query.
*
* @param document The snapshot of the document to end at.
*
* @return The created `Query`.
*/
- (FIRQuery *)queryEndingAtDocument:(FIRDocumentSnapshot *)document NS_SWIFT_NAME(end(atDocument:));
/**
* Creates and returns a new `Query` that ends at the provided fields relative to the order of
* the query. The order of the field values must match the order of the order by clauses of the
* query.
*
* @param fieldValues The field values to end this query at, in order of the query's order by.
*
* @return The created `Query`.
*/
- (FIRQuery *)queryEndingAtValues:(NSArray *)fieldValues NS_SWIFT_NAME(end(at:));
#pragma mark - Aggregation
/**
* A query that counts the documents in the result set of this query without actually downloading
* the documents.
*
* Using this `AggregateQuery` to count the documents is efficient because only the final count, not
* the documents' data, is downloaded. The `AggregateQuery` can count the documents in cases where
* the result set is prohibitively large to download entirely (thousands of documents).
*/
@property(nonatomic, readonly) FIRAggregateQuery *count;
/**
* Creates and returns a new `AggregateQuery` that aggregates the documents in the result set
* of this query without actually downloading the documents.
*
* Using an `AggregateQuery` to perform aggregations is efficient because only the final aggregation
* values, not the documents' data, is downloaded. The returned `AggregateQuery` can perform
* aggregations of the documents in cases where the result set is prohibitively large to download
* entirely (thousands of documents).
*
* @param aggregateFields Specifies the aggregate operations to perform on the result set of this
* query.
*
* @return An `AggregateQuery` encapsulating this `Query` and `AggregateField`s, which can be used
* to query the server for the aggregation results.
*/
- (FIRAggregateQuery *)aggregate:(NSArray<FIRAggregateField *> *)aggregateFields
NS_SWIFT_NAME(aggregate(_:));
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,73 @@
/*
* 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 <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@class FIRDocumentChange;
@class FIRQuery;
@class FIRQueryDocumentSnapshot;
@class FIRSnapshotMetadata;
/**
* A `QuerySnapshot` contains zero or more `DocumentSnapshot` objects. It can be enumerated
* using the `documents` property and its size can be inspected with `isEmpty` and
* `count`.
*/
NS_SWIFT_NAME(QuerySnapshot)
@interface FIRQuerySnapshot : NSObject
/** :nodoc: */
- (id)init __attribute__((unavailable("FIRQuerySnapshot cannot be created directly.")));
/**
* The query on which you called `getDocuments` or listened to in order to get this
* `QuerySnapshot`.
*/
@property(nonatomic, strong, readonly) FIRQuery *query;
/** Metadata about this snapshot, concerning its source and if it has local modifications. */
@property(nonatomic, strong, readonly) FIRSnapshotMetadata *metadata;
/** Indicates whether this `QuerySnapshot` is empty (contains no documents). */
@property(nonatomic, readonly, getter=isEmpty) BOOL empty;
/** The count of documents in this `QuerySnapshot`. */
@property(nonatomic, readonly) NSInteger count;
/** An Array of the `DocumentSnapshots` that make up this document set. */
@property(nonatomic, strong, readonly) NSArray<FIRQueryDocumentSnapshot *> *documents;
/**
* An array of the documents that changed since the last snapshot. If this is the first snapshot,
* all documents will be in the list as Added changes.
*/
@property(nonatomic, strong, readonly) NSArray<FIRDocumentChange *> *documentChanges;
/**
* Returns an array of the documents that changed since the last snapshot. If this is the first
* snapshot, all documents will be in the list as Added changes.
*
* @param includeMetadataChanges Whether metadata-only changes (i.e. only
* `DocumentSnapshot.metadata` changed) should be included.
*/
- (NSArray<FIRDocumentChange *> *)documentChangesWithIncludeMetadataChanges:
(BOOL)includeMetadataChanges NS_SWIFT_NAME(documentChanges(includeMetadataChanges:));
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,83 @@
/*
* Copyright 2024 Google LLC
*
* 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 <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
/**
* The source the snapshot listener retrieves data from.
*/
typedef NS_ENUM(NSUInteger, FIRListenSource) {
/**
* The default behavior. The listener attempts to return initial snapshot from cache and retrieve
* up-to-date snapshots from the Firestore server. Snapshot events will be triggered on local
* mutations and server-side updates.
*/
FIRListenSourceDefault,
/**
* The listener retrieves data and listens to updates from the local Firestore cache without
* attempting to send the query to the server. If some documents gets updated as a result from
* other queries, they will be picked up by listeners using the cache.
*
* Note that the data might be stale if the cache hasn't synchronized with recent server-side
* changes.
*/
FIRListenSourceCache
} NS_SWIFT_NAME(ListenSource);
/**
* Options to configure the behavior of `Firestore.addSnapshotListenerWithOptions()`. Instances
* of this class control settings like whether metadata-only changes trigger events and the
* preferred data source.
*/
NS_SWIFT_NAME(SnapshotListenOptions)
@interface FIRSnapshotListenOptions : NSObject
/** The source the snapshot listener retrieves data from. */
@property(nonatomic, readonly) FIRListenSource source;
/** Indicates whether metadata-only changes should trigger snapshot events. */
@property(nonatomic, readonly) BOOL includeMetadataChanges;
/**
* Creates and returns a new `SnapshotListenOptions` object with all properties initialized to their
* default values.
*
* @return The created `SnapshotListenOptions` object.
*/
- (instancetype)init NS_DESIGNATED_INITIALIZER;
/**
* Creates and returns a new `SnapshotListenOptions` object with with all properties of the current
* `SnapshotListenOptions` object plus the new property specifying whether metadata-only changes
* should trigger snapshot events
*
* @return The created `SnapshotListenOptions` object.
*/
- (FIRSnapshotListenOptions *)optionsWithIncludeMetadataChanges:(BOOL)includeMetadataChanges;
/**
* Creates and returns a new `SnapshotListenOptions` object with with all properties of the current
* `SnapshotListenOptions` object plus the new property specifying the source that the snapshot
* listener listens to.
*
* @return The created `SnapshotListenOptions` object.
*/
- (FIRSnapshotListenOptions *)optionsWithSource:(FIRListenSource)source;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,46 @@
/*
* 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 <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
/** Metadata about a snapshot, describing the state of the snapshot. */
NS_SWIFT_NAME(SnapshotMetadata)
@interface FIRSnapshotMetadata : NSObject
/** :nodoc: */
- (instancetype)init NS_UNAVAILABLE;
/**
* Returns `true` if the snapshot contains the result of local writes (e.g. set() or update() calls)
* that have not yet been committed to the backend. If your listener has opted into metadata updates
* (via `includeMetadataChanges:true`) you will receive another snapshot with `hasPendingWrites`
* equal to `false` once the writes have been committed to the backend.
*/
@property(nonatomic, assign, readonly, getter=hasPendingWrites) BOOL pendingWrites;
/**
* Returns `true` if the snapshot was created from cached data rather than guaranteed up-to-date
* server data. If your listener has opted into metadata updates (via `includeMetadataChanges:true`)
* you will receive another snapshot with `isFromCache` equal to `false` once the client has
* received up-to-date data from the backend.
*/
@property(nonatomic, assign, readonly, getter=isFromCache) BOOL fromCache;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,89 @@
/*
* Copyright 2018 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 <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
/**
* A Timestamp represents a point in time independent of any time zone or calendar, represented as
* seconds and fractions of seconds at nanosecond resolution in UTC Epoch time. It is encoded using
* the Proleptic Gregorian Calendar which extends the Gregorian calendar backwards to year one. It
* is encoded assuming all minutes are 60 seconds long, i.e. leap seconds are "smeared" so that no
* leap second table is needed for interpretation. Range is from 0001-01-01T00:00:00Z to
* 9999-12-31T23:59:59.999999999Z. By restricting to that range, we ensure that we can convert to
* and from RFC 3339 date strings.
*
* @see https://github.com/google/protobuf/blob/main/src/google/protobuf/timestamp.proto for the
* reference timestamp definition.
*/
NS_SWIFT_NAME(Timestamp)
@interface FIRTimestamp : NSObject <NSCopying>
/** :nodoc: */
- (instancetype)init NS_UNAVAILABLE;
/**
* Creates a new timestamp.
*
* @param seconds the number of seconds since epoch.
* @param nanoseconds the number of nanoseconds after the seconds.
*/
- (instancetype)initWithSeconds:(int64_t)seconds
nanoseconds:(int32_t)nanoseconds NS_DESIGNATED_INITIALIZER;
/**
* Creates a new timestamp.
*
* @param seconds the number of seconds since epoch.
* @param nanoseconds the number of nanoseconds after the seconds.
*/
+ (instancetype)timestampWithSeconds:(int64_t)seconds nanoseconds:(int32_t)nanoseconds;
/** Creates a new timestamp from the given date. */
+ (instancetype)timestampWithDate:(NSDate *)date;
/** Creates a new timestamp with the current date / time. */
+ (instancetype)timestamp;
/** Returns a new `Date` corresponding to this timestamp. This may lose precision. */
- (NSDate *)dateValue;
/**
* Returns the result of comparing the receiver with another timestamp.
* @param other the other timestamp to compare.
* @return `orderedAscending` if `other` is chronologically following self,
* `orderedDescending` if `other` is chronologically preceding self,
* `orderedSame` otherwise.
*/
- (NSComparisonResult)compare:(FIRTimestamp *)other;
/**
* Represents seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z.
* Must be from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z inclusive.
*/
@property(nonatomic, assign, readonly) int64_t seconds;
/**
* Non-negative fractions of a second at nanosecond resolution. Negative second values with
* fractions must still have non-negative nanos values that count forward in time.
* Must be from 0 to 999,999,999 inclusive.
*/
@property(nonatomic, assign, readonly) int32_t nanoseconds;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,130 @@
/*
* 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 <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@class FIRDocumentReference;
@class FIRDocumentSnapshot;
/**
* `Transaction` provides methods to read and write data within a transaction.
*
* @see `Firestore.runTransaction(_:)`
*/
NS_SWIFT_NAME(Transaction)
@interface FIRTransaction : NSObject
/** :nodoc: */
- (id)init __attribute__((unavailable("FIRTransaction cannot be created directly.")));
/**
* Writes to the document referred to by `document`. If the document doesn't yet exist,
* this method creates it and then sets the data. If the document exists, this method overwrites
* the document data with the new values.
*
* @param data A `Dictionary` that contains the fields and data to write to the document.
* @param document A reference to the document whose data should be overwritten.
* @return This `Transaction` instance. Used for chaining method calls.
*/
// clang-format off
- (FIRTransaction *)setData:(NSDictionary<NSString *, id> *)data
forDocument:(FIRDocumentReference *)document
NS_SWIFT_NAME(setData(_:forDocument:));
// clang-format on
/**
* Writes to the document referred to by `document`. If the document doesn't yet exist,
* this method creates it and then sets the data. If you pass `merge:true`, the provided data will
* be merged into any existing document.
*
* @param data A `Dictionary` that contains the fields and data to write to the document.
* @param document A reference to the document whose data should be overwritten.
* @param merge Whether to merge the provided data into any existing document. If enabled,
* all omitted fields remain untouched. If your input sets any field to an empty dictionary, any
* nested field is overwritten.
* @return This `Transaction` instance. Used for chaining method calls.
*/
// clang-format off
- (FIRTransaction *)setData:(NSDictionary<NSString *, id> *)data
forDocument:(FIRDocumentReference *)document
merge:(BOOL)merge
NS_SWIFT_NAME(setData(_:forDocument:merge:));
// clang-format on
/**
* Writes to the document referred to by `document` and only replace the fields
* specified under `mergeFields`. Any field that is not specified in `mergeFields`
* is ignored and remains untouched. If the document doesn't yet exist,
* this method creates it and then sets the data.
*
* It is an error to include a field in `mergeFields` that does not have a corresponding
* value in the `data` dictionary.
*
* @param data A `Dictionary` containing the fields that make up the document
* to be written.
* @param document A reference to the document whose data should be overwritten.
* @param mergeFields An `Array` that contains a list of `String` or `FieldPath` elements
* specifying which fields to merge. Fields can contain dots to reference nested fields within
* the document. If your input sets any field to an empty dictionary, any nested field is
* overwritten.
* @return This `Transaction` instance. Used for chaining method calls.
*/
// clang-format off
- (FIRTransaction *)setData:(NSDictionary<NSString *, id> *)data
forDocument:(FIRDocumentReference *)document
mergeFields:(NSArray<id> *)mergeFields
NS_SWIFT_NAME(setData(_:forDocument:mergeFields:));
// clang-format on
/**
* Updates fields in the document referred to by `document`.
* If the document does not exist, the transaction will fail.
*
* @param fields A `Dictionary` containing the fields (expressed as an `String` or
* `FieldPath`) and values with which to update the document.
* @param document A reference to the document whose data should be updated.
* @return This `Transaction` instance. Used for chaining method calls.
*/
// clang-format off
- (FIRTransaction *)updateData:(NSDictionary<id, id> *)fields
forDocument:(FIRDocumentReference *)document
NS_SWIFT_NAME(updateData(_:forDocument:));
// clang-format on
/**
* Deletes the document referred to by `document`.
*
* @param document A reference to the document that should be deleted.
* @return This `Transaction` instance. Used for chaining method calls.
*/
- (FIRTransaction *)deleteDocument:(FIRDocumentReference *)document
NS_SWIFT_NAME(deleteDocument(_:));
/**
* Reads the document referenced by `document`.
*
* @param document A reference to the document to be read.
* @param error An out parameter to capture an error, if one occurred.
*/
- (FIRDocumentSnapshot *_Nullable)getDocument:(FIRDocumentReference *)document
error:(NSError *__autoreleasing *)error
NS_SWIFT_NAME(getDocument(_:));
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,40 @@
/*
* Copyright 2022 Google LLC
*
* 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 <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
/**
* Options to customize the behavior of `Firestore.runTransactionWithOptions()`.
*/
NS_SWIFT_NAME(TransactionOptions)
@interface FIRTransactionOptions : NSObject <NSCopying>
/**
* Creates and returns a new `TransactionOptions` object with all properties initialized to their
* default values.
*
* @return The created `TransactionOptions` object.
*/
- (instancetype)init NS_DESIGNATED_INITIALIZER;
/** The maximum number of attempts to commit, after which transaction fails. Default is 5. */
@property(nonatomic, assign) NSInteger maxAttempts;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,138 @@
/*
* 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 <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@class FIRDocumentReference;
/**
* A write batch is used to perform multiple writes as a single atomic unit.
*
* A WriteBatch object can be acquired by calling `Firestore.batch()`. It provides methods for
* adding writes to the write batch. None of the writes will be committed (or visible locally)
* until `WriteBatch.commit()` is called.
*
* Unlike transactions, write batches are persisted offline and therefore are preferable when you
* don't need to condition your writes on read data.
*/
NS_SWIFT_NAME(WriteBatch)
@interface FIRWriteBatch : NSObject
/** :nodoc: */
- (id)init __attribute__((unavailable("FIRWriteBatch cannot be created directly.")));
/**
* Writes to the document referred to by `document`. If the document doesn't yet exist,
* this method creates it and then sets the data. If the document exists, this method overwrites
* the document data with the new values.
*
* @param data A `Dictionary` that contains the fields and data to write to the document.
* @param document A reference to the document whose data should be overwritten.
* @return This `WriteBatch` instance. Used for chaining method calls.
*/
// clang-format off
- (FIRWriteBatch *)setData:(NSDictionary<NSString *, id> *)data
forDocument:(FIRDocumentReference *)document NS_SWIFT_NAME(setData(_:forDocument:));
// clang-format on
/**
* Writes to the document referred to by `document`. If the document doesn't yet exist,
* this method creates it and then sets the data. If you pass `merge:true`, the provided data will
* be merged into any existing document.
*
* @param data A `Dictionary` that contains the fields and data to write to the document.
* @param document A reference to the document whose data should be overwritten.
* @param merge Whether to merge the provided data into any existing document. If enabled,
* all omitted fields remain untouched. If your input sets any field to an empty dictionary, any
* nested field is overwritten.
* @return This `WriteBatch` instance. Used for chaining method calls.
*/
// clang-format off
- (FIRWriteBatch *)setData:(NSDictionary<NSString *, id> *)data
forDocument:(FIRDocumentReference *)document
merge:(BOOL)merge
NS_SWIFT_NAME(setData(_:forDocument:merge:));
// clang-format on
/**
* Writes to the document referred to by `document` and only replace the fields
* specified under `mergeFields`. Any field that is not specified in `mergeFields`
* is ignored and remains untouched. If the document doesn't yet exist,
* this method creates it and then sets the data.
*
* It is an error to include a field in `mergeFields` that does not have a corresponding
* value in the `data` dictionary.
*
* @param data A `Dictionary` that contains the fields and data to write to the document.
* @param document A reference to the document whose data should be overwritten.
* @param mergeFields An `Array` that contains a list of `String` or `FieldPath` elements
* specifying which fields to merge. Fields can contain dots to reference nested fields within
* the document. If your input sets any field to an empty dictionary, any nested field is
* overwritten.
* @return This `WriteBatch` instance. Used for chaining method calls.
*/
// clang-format off
- (FIRWriteBatch *)setData:(NSDictionary<NSString *, id> *)data
forDocument:(FIRDocumentReference *)document
mergeFields:(NSArray<id> *)mergeFields
NS_SWIFT_NAME(setData(_:forDocument:mergeFields:));
// clang-format on
/**
* Updates fields in the document referred to by `document`.
* If document does not exist, the write batch will fail.
*
* @param fields A `Dictionary` containing the fields (expressed as an `String` or
* `FieldPath`) and values with which to update the document.
* @param document A reference to the document whose data should be updated.
* @return This `WriteBatch` instance. Used for chaining method calls.
*/
// clang-format off
- (FIRWriteBatch *)updateData:(NSDictionary<id, id> *)fields
forDocument:(FIRDocumentReference *)document
NS_SWIFT_NAME(updateData(_:forDocument:));
// clang-format on
/**
* Deletes the document referred to by `document`.
*
* @param document A reference to the document that should be deleted.
* @return This `WriteBatch` instance. Used for chaining method calls.
*/
- (FIRWriteBatch *)deleteDocument:(FIRDocumentReference *)document
NS_SWIFT_NAME(deleteDocument(_:));
/**
* Commits all of the writes in this write batch as a single atomic unit.
*/
- (void)commit;
/**
* Commits all of the writes in this write batch as a single atomic unit.
*
* @param completion A block to be called once all of the writes in the batch have been
* successfully written to the backend as an atomic unit. This block will only execute
* when the client is online and the commit has completed against the server. The
* completion handler will not be called when the device is offline, though local
* changes will be visible immediately.
*/
- (void)commitWithCompletion:(nullable void (^)(NSError *_Nullable error))completion;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,42 @@
/*
* 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 "FIRAggregateField.h"
#import "FIRAggregateQuery.h"
#import "FIRAggregateQuerySnapshot.h"
#import "FIRAggregateSource.h"
#import "FIRCollectionReference.h"
#import "FIRDocumentChange.h"
#import "FIRDocumentReference.h"
#import "FIRDocumentSnapshot.h"
#import "FIRFieldPath.h"
#import "FIRFieldValue.h"
#import "FIRFilter.h"
#import "FIRFirestore.h"
#import "FIRFirestoreErrors.h"
#import "FIRFirestoreSettings.h"
#import "FIRGeoPoint.h"
#import "FIRListenerRegistration.h"
#import "FIRLoadBundleTask.h"
#import "FIRLocalCacheSettings.h"
#import "FIRQuery.h"
#import "FIRQuerySnapshot.h"
#import "FIRSnapshotListenOptions.h"
#import "FIRSnapshotMetadata.h"
#import "FIRTimestamp.h"
#import "FIRTransaction.h"
#import "FIRTransactionOptions.h"
#import "FIRWriteBatch.h"