내용은 잘 모르겠음. 추후 공부해야되는 내용
Hex Code 문자열로 변경해 주는거 같은데 정확한 Hasher() 함수의 기능에 대해서는 잘 모름.ㅜㅜ
extension Data {
struct HexEncodingOptions: OptionSet {
let rawValue: Int
static let upperCase = HexEncodingOptions(rawValue: 1 << 0)
}
func hexEncodedString(options: HexEncodingOptions = []) -> String {
let hexDigits = Array((options.contains(.upperCase) ? "0123456789ABCDEF" : "0123456789abcdef").utf16)
var chars: [unichar] = []
chars.reserveCapacity(2 * count)
for byte in self {
chars.append(hexDigits[Int(byte / 16)])
chars.append(hexDigits[Int(byte % 16)])
}
return String(utf16CodeUnits: chars, count: chars.count)
}
}
[사용방법]
var hasher = Hasher()
hasher.combine("787899")
hasher.bombine("1022032")
var hashValue = hasher.finalize()
var data = Data()
//data.append(UnsafeBufferPointer(start: &hashValue, count: 1))
withUnsafePointer(to: &hashValue) {
data.append(UnsafeBufferPointer(start: $0, count: 1))
}
log(direction: .ETC, ofType: self, datas: data.hexEncodedString())
'Swift > 문법' 카테고리의 다른 글
[SWIFT]DispatchSourceTimer 사용 (0) | 2023.07.03 |
---|---|
[SWIFT]UnsafeBufferPosinter "Initialization of 'UnsafeBufferPointer<Int>' results in a dangling buffer pointer" (0) | 2023.07.03 |
[SWIFT]enum StreenType (화면 회전 정보) (0) | 2023.06.27 |
[SWIFT]Array sorted / map (0) | 2023.06.27 |
[SWIFT]Safe Array 사용하기 (0) | 2023.06.27 |