Swift NSData 初始化
Swift NSData Initialiser
我想从 Obj-C 库中实现这个方法。
func bleDidReceiveData(data: UnsafeMutablePointer<UInt8>, length: Int32) {
var d = NSData(bytes: data as [UInt8], length: length)
}
然而,当我尝试初始化 NSData 时,它给了我这个错误
Cannot find an initialiser for type NSData that accepts an argument of type (bytes:[UInt8],length:int32)
在 Obj-C 中就是这样完成的
NSData *d = [NSData dataWithBytes:data length:length];
func bleDidReceiveData(data: UnsafeMutablePointer<UInt8>, length: Int32) {
var d = NSData(bytes: UnsafeMutablePointer<Void>(data), length: Int(length))
}
我想从 Obj-C 库中实现这个方法。
func bleDidReceiveData(data: UnsafeMutablePointer<UInt8>, length: Int32) {
var d = NSData(bytes: data as [UInt8], length: length)
}
然而,当我尝试初始化 NSData 时,它给了我这个错误
Cannot find an initialiser for type NSData that accepts an argument of type (bytes:[UInt8],length:int32)
在 Obj-C 中就是这样完成的
NSData *d = [NSData dataWithBytes:data length:length];
func bleDidReceiveData(data: UnsafeMutablePointer<UInt8>, length: Int32) {
var d = NSData(bytes: UnsafeMutablePointer<Void>(data), length: Int(length))
}