我想弄清楚,为什么,如果我在if
和else
行上设置断点,为什么我的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)
}
我是在忘记工作还是只是愚蠢?可以请有人解释我这个。
答案 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
}