Can anyone please help me update this for loop to swift 3.0. help appreciated. Thank you!
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)
}
In Swift 3, "Collections move their index", see A New Model for Collections and Indices on Swift evolution. In particular,
advanced the index
fromIndex
by 2 character positions, but only if it fits into the valid range of indices, and returnsnil
otherwise. Therefore the loop can be written as