FIRCollectionReference.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Copyright 2017 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <Foundation/Foundation.h>
  17. #import "FIRQuery.h"
  18. NS_ASSUME_NONNULL_BEGIN
  19. @class FIRDocumentReference;
  20. /**
  21. * A `CollectionReference` object can be used for adding documents, getting document references,
  22. * and querying for documents (using the methods inherited from `Query`).
  23. */
  24. NS_SWIFT_SENDABLE
  25. NS_SWIFT_NAME(CollectionReference)
  26. @interface FIRCollectionReference : FIRQuery
  27. /** :nodoc: */
  28. - (id)init __attribute__((unavailable("FIRCollectionReference cannot be created directly.")));
  29. /** ID of the referenced collection. */
  30. @property(nonatomic, strong, readonly) NSString *collectionID;
  31. /**
  32. * For subcollections, `parent` returns the containing `DocumentReference`. For root collections,
  33. * `nil` is returned.
  34. */
  35. @property(nonatomic, strong, nullable, readonly) FIRDocumentReference *parent;
  36. /**
  37. * A string containing the slash-separated path to this this `CollectionReference` (relative to the
  38. * root of the database).
  39. */
  40. @property(nonatomic, strong, readonly) NSString *path;
  41. /**
  42. * Returns a `DocumentReference` pointing to a new document with an auto-generated ID.
  43. *
  44. * @return A `DocumentReference` pointing to a new document with an auto-generated ID.
  45. */
  46. - (FIRDocumentReference *)documentWithAutoID NS_SWIFT_NAME(document());
  47. /**
  48. * Gets a `DocumentReference` referring to the document at the specified path, relative to this
  49. * collection's own path.
  50. *
  51. * @param documentPath The slash-separated relative path of the document for which to get a
  52. * `DocumentReference`.
  53. *
  54. * @return The `DocumentReference` for the specified document path.
  55. */
  56. - (FIRDocumentReference *)documentWithPath:(NSString *)documentPath NS_SWIFT_NAME(document(_:));
  57. /**
  58. * Adds a new document to this collection with the specified data, assigning it a document ID
  59. * automatically.
  60. *
  61. * @param data A `Dictionary` containing the data for the new document.
  62. *
  63. * @return A `DocumentReference` pointing to the newly created document.
  64. */
  65. - (FIRDocumentReference *)addDocumentWithData:(NSDictionary<NSString *, id> *)data
  66. NS_SWIFT_NAME(addDocument(data:));
  67. /**
  68. * Adds a new document to this collection with the specified data, assigning it a document ID
  69. * automatically.
  70. *
  71. * @param data A `Dictionary` containing the data for the new document.
  72. * @param completion A block to execute once the document has been successfully written to
  73. * the server. This block will not be called while the client is offline, though local
  74. * changes will be visible immediately.
  75. *
  76. * @return A `DocumentReference` pointing to the newly created document.
  77. */
  78. // clang-format off
  79. // clang-format breaks the NS_SWIFT_NAME attribute
  80. - (FIRDocumentReference *)addDocumentWithData:(NSDictionary<NSString *, id> *)data
  81. completion:
  82. (nullable void (^)(NSError *_Nullable error))completion
  83. NS_SWIFT_NAME(addDocument(data:completion:));
  84. // clang-format on
  85. @end
  86. NS_ASSUME_NONNULL_END