Skip to content

Commit 891a44d

Browse files
authored
Merge pull request #60787 from hyp/eng/string-2-nsstring-docs
[interop][SwiftToCxx] docs: add section on converting Swift's String …
2 parents af9c1bb + 64b90e8 commit 891a44d

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

docs/CppInteroperability/UserGuide-CallingSwiftFromC++.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,6 +1323,16 @@ void setSwiftString(swift::String &other, const std::string &str) {
13231323
}
13241324
```
13251325

1326+
In Objective-C++ mode, you can also convert a `swift::String` to an `NSString *` value using
1327+
a cast or by assigning to an `NSString *` value directly:
1328+
1329+
```c++
1330+
void useObjCString(const swift::String &swStr) {
1331+
// This cast will bridge the Swift String to an Objective-C NSString value.
1332+
NSString *nsStr = swStr;
1333+
}
1334+
```
1335+
13261336
Open questions:
13271337
13281338
* How do the `StringLiteralConvertible` rules work in practice?

0 commit comments

Comments
 (0)