'withUnsafeBytes' is deprecated

As @David_Smith said, the withUnsafeBytes() method passing a typed pointer to the closure has been deprecated in favor of a method which passes a raw pointer to the closure, see also

You can also let the compiler infer the closure parameters automatically (and omit the return keyword for single-expression closures/functions):

func hexString(data: Data) -> String {
    data.withUnsafeBytes {
        $0.map{String(format: "%02hhx", $0)}.reduce("", { $0 + $1 })
    }
}
3 Likes