Convert from C String pointer to Swift String type

code


const char* hoge() {
    char* var = "HELLO WORLD";
    return var;
}

I want to convert the return value of a function that returns such a pointer to a String in swift (assuming a bridge)

code


String(cString: UnsafePointer<CChar>(hoge())!)

Since Swift's String can handle cString Get pointer of CChar type-> convert to cString-> convert to String

If there is a better way, please teach me.

Recommended Posts

Convert from C String pointer to Swift String type
Convert String type to Timestamp type
Convert Swift 2D array to C 2D array
[Java] How to convert a character string from String type to byte type
[Java] Convert Object type null to String type
Type conversion from java BigDecimal type to String type
[Convenient to remember !!!] How to convert from LocalDate type to character string and from character string to LocalDate type
[Java] How to convert from String to Path type and get the path
Convert a string to a character-by-character array with swift
Generate models from JSON to Swift, PHP, C #, JAVA
Convert to Ruby Leet string
Convert from ○ months to ○ years ○ months
Great Swift pointer type commentary
Pass C ++ char * to Swift
I tried to convert a string to a LocalDate type in Java
Change only one character from the String type string to uppercase
I want to convert InputStream to String
Convert iso-2022-jp character string to utf-8
Call a C function from Swift
[Swift] Converts a UInt64 type integer to [UInt8]
[Rails] How to convert from erb to haml
Convert C language to JavaScript with Emscripten
Convert from java UTC time to JST time
How to call Swift 5.3 code from Objective-C
[Flutter] How to use C / C ++ from Dart?
Convert from color temperature to RGB (sRGB)
How to get the date from the JavaScript Date type that C # developers are addicted to
[Swift5] extension that allows UIImage to be specified by a String type URL
[Ruby] How to convert from lowercase to uppercase and from uppercase to lowercase
Convert to a tag to URL string in Rails
[Android] How to convert a character string to resourceId
[Swift] Convert ByteArray and HexString to each other
[Swift] Skill map from inexperienced to practical (roadmap)
[Swift, ARKit] Migrate from deprecated hitTest to raycastQuery
[Swift] Type type ~ Enumeration type ~
[Swift] Type type ~ Structure ~
Launch Docker from Java to convert Office documents to PDF
<java> Read Zip file and convert directly to string
Convert Java enum enums and JSON to and from Jackson
[Swift] How to play songs from your music library
Sample code to convert List to List <String> in Java Stream
[Java] How to erase a specific character from a character string
Ruby Regular Expression Extracts from a specific string to a string
[Kotlin] Convert ZonedDateTime to String by specifying the format
[Urgent recruitment] I can't convert from java.util.date to java.sql.date ...
A memorandum when I investigated how to convert from Epoch Time to Date type in Scala