Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/106.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 使用nsmutabledata swift填充数组_Ios_Arrays_Swift_Byte_Bytearray - Fatal编程技术网

Ios 使用nsmutabledata swift填充数组

Ios 使用nsmutabledata swift填充数组,ios,arrays,swift,byte,bytearray,Ios,Arrays,Swift,Byte,Bytearray,如何在swift中使用nsmutabledata填充数组 这是我的密码: func hashTest(hash:[UInt8]) { var arrayOfBytes = NSMutableData() for var i = 0; i < hash.count; i++ { if i < 21 { arrayOfBytes.appendBytes(hash[i] as UInt8, le

如何在swift中使用nsmutabledata填充数组

这是我的密码:

    func hashTest(hash:[UInt8]) {
        var arrayOfBytes = NSMutableData()
        for var i = 0; i < hash.count; i++ {
            if i < 21 {
                arrayOfBytes.appendBytes(hash[i] as UInt8, length: 1)
            }
        }
    }

只需将
&
放在
散列[i]
前面,这将允许不安全指针进入附加字节

func hashTest(var hash:[UInt8]) {
        var arrayOfBytes = NSMutableData()
        for var i = 0; i < hash.count; i++ {
        if i < 21 {
            arrayOfBytes.appendBytes(&hash[i], length: 1)
        }
    }
}
func散列测试(变量散列:[UInt8]){
var arrayOfBytes=NSMutableData()
对于变量i=0;i
仍然收到一些警告:```&`与类型为'UnsafePointer'(也称为'UnsafePointer')的非inout参数一起使用```我认为您需要将var添加到参数中,因为您正在传入它。@ViniciusAlbino请注意,那些用于var的
循环在Swift 3中不可用。你应该习惯于在
loops@LeoDabus你有文件吗?我以为那只是我最后知道的一个建议
let endMarker = NSData(bytes: [0xa1, 0x11, 0xa9, 0xf5, 0xce, 0xdb, 0x18, 0xfb, 0xed, 0xd7, 0x67, 0x25, 0x86, 0xe7, 0xd6, 0x42, 0x96, 0x0f, 0x95, 0xe8] as [UInt8], length: 20)
func hashTest(var hash:[UInt8]) {
        var arrayOfBytes = NSMutableData()
        for var i = 0; i < hash.count; i++ {
        if i < 21 {
            arrayOfBytes.appendBytes(&hash[i], length: 1)
        }
    }
}