I am replacing all the null checks with let block in my code as part of a code review process.
1. Code example with null check:
if(someValue != null){//run if someValue is not null}
else {//run if someValue is null}
2. Code base after using let-run block if for null check,
var someValue : String? = null
someValue = "SOF"
someValue?.let {safeSomeValue->
//This code block will run only if someValue is not null
}?.run {
//This code block should run only when if someValue is null, like else condition
}
现在,let run块的问题是,即使someValue不为null,两个代码块都在运行.所以我无法复制代码示例1中if-else条件的行为来运行代码示例2中的let条件.
预期行为是根据值是NULL还是非NULL来执行LET或运行代码挡路.