aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--Firestore/Example/Tests/Model/FSTDocumentKeyTests.mm11
-rw-r--r--Firestore/Source/Model/FSTDocumentKey.mm2
-rw-r--r--Firestore/core/src/firebase/firestore/model/document_key.h19
3 files changed, 31 insertions, 1 deletions
diff --git a/Firestore/Example/Tests/Model/FSTDocumentKeyTests.mm b/Firestore/Example/Tests/Model/FSTDocumentKeyTests.mm
index 5992b42..5e465f7 100644
--- a/Firestore/Example/Tests/Model/FSTDocumentKeyTests.mm
+++ b/Firestore/Example/Tests/Model/FSTDocumentKeyTests.mm
@@ -18,8 +18,10 @@
#import <XCTest/XCTest.h>
+#include "Firestore/core/src/firebase/firestore/model/document_key.h"
#include "Firestore/core/src/firebase/firestore/model/resource_path.h"
+using firebase::firestore::model::DocumentKey;
using firebase::firestore::model::ResourcePath;
NS_ASSUME_NONNULL_BEGIN
@@ -56,6 +58,15 @@ NS_ASSUME_NONNULL_BEGIN
XCTAssertEqual(NSOrderedDescending, [ab compare:a]);
}
+- (void)testConverter {
+ const ResourcePath path{"rooms", "firestore", "messages", "1"};
+ FSTDocumentKey *objcKey = [FSTDocumentKey keyWithPath:path];
+ XCTAssertEqualObjects(objcKey, (FSTDocumentKey *)(DocumentKey{objcKey}));
+
+ DocumentKey cpp_key{path};
+ XCTAssertEqual(cpp_key, DocumentKey{(FSTDocumentKey *)(cpp_key)});
+}
+
@end
NS_ASSUME_NONNULL_END
diff --git a/Firestore/Source/Model/FSTDocumentKey.mm b/Firestore/Source/Model/FSTDocumentKey.mm
index 269748f..7425812 100644
--- a/Firestore/Source/Model/FSTDocumentKey.mm
+++ b/Firestore/Source/Model/FSTDocumentKey.mm
@@ -101,7 +101,7 @@ NS_ASSUME_NONNULL_BEGIN
return path.size() % 2 == 0;
}
-- (const firebase::firestore::model::ResourcePath &)path {
+- (const ResourcePath &)path {
return _path;
}
diff --git a/Firestore/core/src/firebase/firestore/model/document_key.h b/Firestore/core/src/firebase/firestore/model/document_key.h
index 6eb1e18..8e590d8 100644
--- a/Firestore/core/src/firebase/firestore/model/document_key.h
+++ b/Firestore/core/src/firebase/firestore/model/document_key.h
@@ -21,6 +21,10 @@
#include <memory>
#include <string>
+#if defined(__OBJC__)
+#import "Firestore/Source/Model/FSTDocumentKey.h"
+#endif // defined(__OBJC__)
+
#include "Firestore/core/src/firebase/firestore/model/resource_path.h"
#include "absl/strings/string_view.h"
@@ -43,6 +47,16 @@ class DocumentKey {
/** Creates a new document key, taking ownership of the given path. */
explicit DocumentKey(ResourcePath&& path);
+#if defined(__OBJC__)
+ DocumentKey(FSTDocumentKey* key) // NOLINT(runtime/explicit)
+ : path_(std::make_shared<ResourcePath>(key.path)) {
+ }
+
+ operator FSTDocumentKey*() const {
+ return [FSTDocumentKey keyWithPath:path()];
+ }
+#endif
+
/**
* Creates and returns a new document key using '/' to split the string into
* segments.
@@ -69,6 +83,11 @@ class DocumentKey {
return path_ ? *path_ : Empty().path();
}
+#if defined(__OBJC__)
+ // Helper function to convert to FSTDocumentKey during the C++ migration.
+ FSTDocumentKey* ToFSTDocumentKey() const;
+#endif // defined(__OBJC__)
+
private:
// This is an optimization to make passing DocumentKey around cheaper (it's
// copied often).