Hi I am converting existing swift 2.0 code to swift 3.0 but came across an error while conversion:
Cannot invoke initializer for type 'UnsafePointer' with an argument list of type '(UnsafeRawPointer)'
Here is my code:
extension Data { var hexString : String { let buf = UnsafePointer<UInt8>(bytes) // here is the error let charA = UInt8(UnicodeScalar("a").value) let char0 = UInt8(UnicodeScalar("0").value) func itoh(_ i: UInt8) -> UInt8 { return (i > 9) ? (charA + i - 10) : (char0 + i) } let p = UnsafeMutablePointer<UInt8>.allocate(capacity: count * 2) for i in 0..<count { p[i*2] = itoh((buf[i] >> 4) & 0xF) p[i*2+1] = itoh(buf[i] & 0xF) } return NSString(bytesNoCopy: p, length: count*2, encoding: String.Encoding.utf8.rawValue, freeWhenDone: true)! as String } }
var hexString : String { return self.map { String(format:"%02x", $0) }.joined() }?