在给定范围的上下文中包含defer
语句的位置是否重要?这些都是一样的吗?
//1
{
openFile();
guard let x=y else {
return
}
defer {
closeFile()
}
}
//2
{
openFile();
defer {
closeFile()
}
guard let x=y else {
return
}
}
//3
{
defer {
closeFile()
}
openFile();
guard let x=y else {
return
}
}