I have an UnsafeMutablePointer<Character>
filled by a CoreFoundation method.
If I NSLog it with %s
placeholder, it outputs just fine.
But if I try with Swift's print
it just writes the memory address.
Tried nearly everything... also I don't understand why if I try to access the underlying memory
property I get a EXC_BAD_ACCESS
.
let deviceName = UnsafeMutablePointer<Character>.alloc(64)
/* other statements in which deviceName is filled */
NSLog("device %s by %s", deviceName, manufacturerName)
// Outputs correctly the string
print(String(deviceName[0]))
// Get an EXC_BAD_ACCESS error at runtime
print(String(deviceName.memory))
// Get an EXC_BAD_ACCESS error at runtime
let str = withUnsafePointer(&deviceName) { String.fromCString(UnsafePointer($0)) }
print(str)
// Outputs an empty string
print("\(deviceName) by \(manufacturerName)")
// Outputs just memory addresses