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

时间:2018-02-28 21:51:31

标签: swift if-statement

我想弄清楚,为什么,如果我在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)

}

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

1 个答案:

答案 0 :(得分: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
}
相关问题