所以,我试图有一种有效地做到这一点的方法:
- (void)doWhile: (/*some magical type*/)condition
{
while (condition)
{
// do some magical things
}
}
虽然您的第一个建议可能是BOOL
考虑以下例外情况:
[someObject doWhile: someOtherObject];
// yes, I know that I could just do (someOtherObject != nil), but
// I should be able to just use (someOtherObject), right?
// seeing as how ifs/fors/whiles can use just the object.
[someObject doWhile: [someOtherObject isValid]];
// since -isValid returns a BOOL, this will work, but it will only
// pass the value of -isValid at the time of calling to the while loop.
// if the value of -isValid changes, -doWhile: will have no idea of the change,
// whereas while() would.
原语的使用_Bool
使我能够解决前一个问题,但后一个问题仍然存在。是否有某种方法可以评估与类型无关的参数的真实性与while()
工作方式相同?