aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firestore/Source/Public/FIRCollectionReference.h
blob: bc9a56af932c01d655524eab5a37fb8231d395c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
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 `FIRCollectionReference` object can be used for adding documents, getting document references,
 * and querying for documents (using the methods inherited from `FIRQuery`).
 */
NS_SWIFT_NAME(CollectionReference)
@interface FIRCollectionReference : FIRQuery

/**   */
- (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 `FIRDocumentReference`.  For root
 * collections, nil is returned.
 */
@property(nonatomic, strong, nullable, readonly) FIRDocumentReference *parent;

/**
 * A string containing the slash-separated path to this this `FIRCollectionReference` (relative to
 * the root of the database).
 */
@property(nonatomic, strong, readonly) NSString *path;

/**
 * Returns a FIRDocumentReference pointing to a new document with an auto-generated ID.
 *
 * @return A FIRDocumentReference pointing to a new document with an auto-generated ID.
 */
- (FIRDocumentReference *)documentWithAutoID NS_SWIFT_NAME(document());

/**
 * Gets a `FIRDocumentReference` 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
 * `FIRDocumentReference`.
 *
 * @return The `FIRDocumentReference` for the specified document path.
 */
- (FIRDocumentReference *)documentWithPath:(NSString *)documentPath NS_SWIFT_NAME(document(_:));

/**
 * Add a new document to this collection with the specified data, assigning it  a document ID
 * automatically.
 *
 * @param data An `NSDictionary` containing the data for the new document.
 *
 * @return A `FIRDocumentReference` pointing to the newly created document.
 */
- (FIRDocumentReference *)addDocumentWithData:(NSDictionary<NSString *, id> *)data
    NS_SWIFT_NAME(addDocument(data:));

/**
 * Add a new document to this collection with the specified data, assigning it a document ID
 * automatically.
 *
 * @param data An `NSDictionary` 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 `FIRDocumentReference` 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