I have a library which has a function like this:
int get_user_name(const char **buffer);
in swift, should call like this:
var name:CMutablePointer<CString> = nil
get_user_name(name)
I want make use this function more comfortable so I wrapped this up:
func get_username() -> String {
var name:CMutablePointer<CString> = nil
get_user_name(name)
// how to convert name to String
}
I question is how to convert name to String
It goes something like:
var stringValue :CString = ""
name.withUnsafePointer {p in
stringValue = p.memory
}
return NSString(CString: stringValue)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With