18 lines
314 B
Swift
18 lines
314 B
Swift
|
import Foundation
|
||
|
|
||
|
extension Data {
|
||
|
|
||
|
func convert<T>(into value: T) -> T {
|
||
|
withUnsafeBytes {
|
||
|
$0.baseAddress!.load(as: T.self)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
init<T>(from value: T) {
|
||
|
var target = value
|
||
|
self = Swift.withUnsafeBytes(of: &target) {
|
||
|
Data($0)
|
||
|
}
|
||
|
}
|
||
|
}
|