FIRCollectionReference.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 `FIRCollectionReference` object can be used for adding documents, getting document references,
  22. * and querying for documents (using the methods inherited from `FIRQuery`).
  23. */
  24. NS_SWIFT_NAME(CollectionReference)
  25. @interface FIRCollectionReference : FIRQuery
  26. /** :nodoc: */
  27. - (id)init __attribute__((unavailable("FIRCollectionReference cannot be created directly.")));
  28. /** ID of the referenced collection. */
  29. @property(nonatomic, strong, readonly) NSString *collectionID;
  30. /**
  31. * For subcollections, `parent` returns the containing `FIRDocumentReference`. For root
  32. * collections, nil is returned.
  33. */
  34. @property(nonatomic, strong, nullable, readonly) FIRDocumentReference *parent;
  35. /**
  36. * A string containing the slash-separated path to this this `FIRCollectionReference` (relative to
  37. * the root of the database).
  38. */
  39. @property(nonatomic, strong, readonly) NSString *path;
  40. /**
  41. * Returns a FIRDocumentReference pointing to a new document with an auto-generated ID.
  42. *
  43. * @return A FIRDocumentReference pointing to a new document with an auto-generated ID.
  44. */
  45. - (FIRDocumentReference *)documentWithAutoID NS_SWIFT_NAME(document());
  46. /**
  47. * Gets a `FIRDocumentReference` referring to the document at the specified path, relative to this
  48. * collection's own path.
  49. *
  50. * @param documentPath The slash-separated relative path of the document for which to get a
  51. * `FIRDocumentReference`.
  52. *
  53. * @return The `FIRDocumentReference` for the specified document path.
  54. */
  55. - (FIRDocumentReference *)documentWithPath:(NSString *)documentPath NS_SWIFT_NAME(document(_:));
  56. /**
  57. * Adds a new document to this collection with the specified data, assigning it a document ID
  58. * automatically.
  59. *
  60. * @param data An `NSDictionary` containing the data for the new document.
  61. *
  62. * @return A `FIRDocumentReference` pointing to the newly created document.
  63. */
  64. - (FIRDocumentReference *)addDocumentWithData:(NSDictionary<NSString *, id> *)data
  65. NS_SWIFT_NAME(addDocument(data:));
  66. /**
  67. * Adds a new document to this collection with the specified data, assigning it a document ID
  68. * automatically.
  69. *
  70. * @param data An `NSDictionary` containing the data for the new document.
  71. * @param completion A block to execute once the document has been successfully written to
  72. * the server. This block will not be called while the client is offline, though local
  73. * changes will be visible immediately.
  74. *
  75. * @return A `FIRDocumentReference` pointing to the newly created document.
  76. */
  77. // clang-format off
  78. // clang-format breaks the NS_SWIFT_NAME attribute
  79. - (FIRDocumentReference *)addDocumentWithData:(NSDictionary<NSString *, id> *)data
  80. completion:
  81. (nullable void (^)(NSError *_Nullable error))completion
  82. NS_SWIFT_NAME(addDocument(data:completion:));
  83. // clang-format on
  84. @end
  85. NS_ASSUME_NONNULL_END