Ramis Ramis - 1 year ago 78
iOS Question

How to fix C-style for statement?

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...

Answer Source

You could convert the for loop into a while loop:

var ptr = ifaddr
while ptr != nil {
    // Do stuff
    ptr = ptr.memory.ifa_next