Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.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 从swift 3.0中删除的语句的C样式,后续()不可用_Ios_Swift_Swift3 - Fatal编程技术网

Ios 从swift 3.0中删除的语句的C样式,后续()不可用

Ios 从swift 3.0中删除的语句的C样式,后续()不可用,ios,swift,swift3,Ios,Swift,Swift3,有人能帮我把这个for循环更新到swift 3.0吗。谢谢你的帮助。谢谢大家! for var index = trimmedString.startIndex; index < trimmedString.endIndex; index = index.successor().successor() { let byteString = trimmedString.substringWithRange(Range<String.Index>(start: i

有人能帮我把这个for循环更新到swift 3.0吗。谢谢你的帮助。谢谢大家!

for var index = trimmedString.startIndex; index < trimmedString.endIndex; index = index.successor().successor() {

        let byteString = trimmedString.substringWithRange(Range<String.Index>(start: index, end: index.successor().successor()))
        let num = UInt8(byteString.withCString { strtoul($0, nil, 16) })
        data?.appendBytes([num] as [UInt8], length: 1)

    }
var指数=trimmedString.startIndex的
;index
在Swift 3中,“集合移动其索引”,请参见 关于快速进化。特别是,

let toIndex = string.index(fromIndex, offsetBy: 2, limitedBy: string.endIndex)
将索引
从index
提升2个字符位置,但仅限于 如果它符合有效的索引范围,并返回
nil
否则。因此,循环可以写为

let string = "0123456789abcdef"
let data = NSMutableData()

var fromIndex = string.startIndex
while let toIndex = string.index(fromIndex, offsetBy: 2, limitedBy: string.endIndex) {

    // Extract hex code at position fromIndex ..< toIndex:
    let byteString = string.substring(with: fromIndex..<toIndex)
    var num = UInt8(byteString.withCString { strtoul($0, nil, 16) })
    data.append(&num, length: 1)

    // Advance to next position:
    fromIndex = toIndex
}

print(data) // <01234567 89abcdef>
let string=“0123456789abcdef”
let data=NSMutableData()
var fromIndex=string.startIndex
而let-toIndex=string.index(fromIndex,offsetBy:2,limitedBy:string.endIndex){
//从索引..let byteString=string.substring(with:fromIndex..嘿,谢谢你,我不确定offsetBy参数?其意义是什么?@shashashantdahikar:正如我所说,
offsetBy:2
将索引增加两倍,就像
在Swift 2代码中一样。