Continue is allowed only inside the loop

Is this a bug in Swift where any code placed inside an autoreleasepool thinks it is not inside a loop? Is there a workaround to do this and then do messy code by splitting my code into multiple autorun pools?

for (key, value) in dictionary {
    autoreleasepool {
        // Lots of allocation and lots of logic

        continue // Need to continue to the next loop

        // Lots of allocation and lots of logic
    }
}

      

+3


source to share


1 answer


The argument autoreleasepool

is a closure, so you can just go back from the closure:



for (key, value) in dictionary {
    autoreleasepool {
        // Lots of allocation and lots of logic

        if someCondition { return } // Need to continue to the next loop

        // Lots of allocation and lots of logic
    }
}

      

+13


source







All Articles