だから、私はこれを効果的に行う方法を作ろうとしています:
- (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()
か?