// // DataExtension.swift // SWCompression // // Created by Timofey Solomko on 19.09.16. // Copyright © 2016 Timofey Solomko. All rights reserved. // import Foundation extension Data { func to(type: T.Type) -> T { return self.withUnsafeBytes { $0.pointee } } func toArray(type: T.Type) -> [T] { return self.withUnsafeBytes { [T](UnsafeBufferPointer(start: $0, count: self.count/MemoryLayout.size)) } } } extension UInt8 { func toInt() -> Int { return Int(bitPattern: UInt(self)) } } extension Int { func toUInt8() -> UInt8 { return UInt8(truncatingBitPattern: UInt(self)) } }