为什么断点在'if else'条件下的else块中断

问题描述 投票:0回答:1

我想弄清楚,为什么,如果我在ifelse线上设置断点,为什么我的if else {}条件在else上断,如果条件是在true区块的if

我正在使用领域,但我不认为,这是一个问题。

//Check if Object already exists in database
if !RealmService.shared.ifPortfolioExists(name: portfolio.name){//Breakpoint on this line which is true

     //Create portfolio
     RealmService.shared.create(portfolio)
     //Assign portfolio to transaction
     transaction.portfolio = portfolio
     //Create transaction
     RealmService.shared.create(transaction)

}else{//Breakpoint on this line

     //Assign portfolio to transaction       
     transaction.portfolio = portfolio
     //Create transaction
     RealmService.shared.create(transaction)

}

我是在忘记工作还是只是愚蠢?可以请有人解释我这个。

swift if-statement
1个回答
0
投票

编译器读取它们以查看它是否应该进入下面的代码块。 if内部的断点将在true时触发,而else在false时触发

这样做是为了更好地了解断点生效的位置:

if x != y {
    print("if breakpoint")//set breakpoint here
} else {
    print("else breakpoint")//set breakpoint here
    // you should see that the breakpoint doesn't fire here
}
© www.soinside.com 2019 - 2024. All rights reserved.