UnsafeMutablePointer to NSString

Converting UnsafeMutablePointer<UInt8> to NSString.

Today I was using a function that was bridging from a third party library in Objective-C.

The function has two parameters, first parameter has a type of UnsafeMutablePointer<UInt8>, second one the type is Int32, which is the length of the char array.  My goal is convert it to NSString for logging information.

UnsafeMutablePointer<UInt8> is an array of char(or bytes) in the library API.

In order to do this, use NSString function:

convenience init?(bytes bytes: a href=”” UnsafePointer <Void >,
length length: Int,
encoding encoding: UInt )

Example:

Read More