0

だから、私はこれを効果的に行う方法を作ろうとしています:

- (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()か?

4

1 に答える 1

0

コメントに記載されているように、完全に動的な評価が必要ないテストケースには、より単純な方法が適切な場合でも、ブロックを渡すことは、目的の結果を取得するための用途の広い方法です。

于 2012-06-03T18:15:19.010 に答える