What is right way to fix C-style for statement for the code which is posted below?
Currently I am getting this warring:
C-style for statement is deprecated and will be removed in a future version of Swift
var ifaddr : UnsafeMutablePointer<ifaddrs> = nil
if getifaddrs(&ifaddr) == 0 {
// Warning
for (var ptr = ifaddr; ptr != nil; ptr = ptr.memory.ifa_next) {
// Do some stuff...
}
}
You could convert the for
loop into a while
loop:
var ptr = ifaddr
while ptr != nil {
// Do stuff
ptr = ptr.memory.ifa_next
}
Here's a version that worked for me.
var ptr = ifaddr
repeat {
ptr = ptr.memory.ifa_next
if ptr != nil {
...
}
} while ptr != nil
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With