这是不是 Swift 中的一个错误,任何放置在自动释放池中的代码都认为它不在循环中?是否有解决此问题的方法,而不是通过将我的代码分成多个自动释放池来制作困惑的代码?
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
}
}
最佳答案
autoreleasepool
的参数是一个闭包,所以你可以提前返回
来自闭包:
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
}
}
关于swift - continue 只允许在循环内,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27584330/