Swift-Data Extension

获得字节数组(属性)

extension Data {
    public var bytes: [UInt8] {
        // http://stackoverflow.com/questions/38097710/swift-3-changes-for-getbytes-method
        return [UInt8](self)
    }
}

通过指定的编码将Data转化为String

extension Data {
    public func string(encoding: String.Encoding) -> String? {
        return String(data: self, encoding: encoding)
    }
}

资源来自网络和日常整理,持续更新

你可能感兴趣的:(Swift-Data Extension)