1. <i id='iDQZu'><tr id='iDQZu'><dt id='iDQZu'><q id='iDQZu'><span id='iDQZu'><b id='iDQZu'><form id='iDQZu'><ins id='iDQZu'></ins><ul id='iDQZu'></ul><sub id='iDQZu'></sub></form><legend id='iDQZu'></legend><bdo id='iDQZu'><pre id='iDQZu'><center id='iDQZu'></center></pre></bdo></b><th id='iDQZu'></th></span></q></dt></tr></i><div id='iDQZu'><tfoot id='iDQZu'></tfoot><dl id='iDQZu'><fieldset id='iDQZu'></fieldset></dl></div>

        <bdo id='iDQZu'></bdo><ul id='iDQZu'></ul>
      1. <legend id='iDQZu'><style id='iDQZu'><dir id='iDQZu'><q id='iDQZu'></q></dir></style></legend>

        <small id='iDQZu'></small><noframes id='iDQZu'>

        <tfoot id='iDQZu'></tfoot>

        在 Objective-c 中,比较 2 个 BOOL 值的安全和好方法?

        时间:2023-10-05

        <legend id='T0t0y'><style id='T0t0y'><dir id='T0t0y'><q id='T0t0y'></q></dir></style></legend>
          • <bdo id='T0t0y'></bdo><ul id='T0t0y'></ul>

              <tbody id='T0t0y'></tbody>
            1. <i id='T0t0y'><tr id='T0t0y'><dt id='T0t0y'><q id='T0t0y'><span id='T0t0y'><b id='T0t0y'><form id='T0t0y'><ins id='T0t0y'></ins><ul id='T0t0y'></ul><sub id='T0t0y'></sub></form><legend id='T0t0y'></legend><bdo id='T0t0y'><pre id='T0t0y'><center id='T0t0y'></center></pre></bdo></b><th id='T0t0y'></th></span></q></dt></tr></i><div id='T0t0y'><tfoot id='T0t0y'></tfoot><dl id='T0t0y'><fieldset id='T0t0y'></fieldset></dl></div>
              • <tfoot id='T0t0y'></tfoot>

                <small id='T0t0y'></small><noframes id='T0t0y'>

                  本文介绍了在 Objective-c 中,比较 2 个 BOOL 值的安全和好方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想比较 Objective-c 中的 2 个 BOOL 值.

                  I want to compare 2 BOOL values in objective-c.

                  我发现以下代码中的 (3)-(6) 有效.
                  (1)-(2) 不起作用,因为 BOOL 只是 signed char.

                  I found out that (3)-(6) of the following code works.
                  (1)-(2) doesn't work because BOOL is just signed char.

                  (3) 有效且可读性强,但我认为 bool 不是 Objective-c.
                  在objective-c代码中使用bool好不好?

                  (3) works and is very readable but I think bool isn't objective-c.
                  Using bool in objective-c code is good?

                  在 Objective-c 中比较 2 个 BOOL 值的安全和好方法是什么?
                  还有其他更好的比较方法吗?

                  Which is the safe and good way to compare 2 BOOL values in objective-c?
                  Are there other better ways to compare?

                  BOOL b = YES;
                  BOOL c = 2;
                  
                  NSLog(@"(1) %d", b == c); // not work
                  NSLog(@"(2) %d", (BOOL)b == (BOOL)c); // not work
                  NSLog(@"(3) %d", (bool)b == (bool)c);
                  NSLog(@"(4) %d", !b == !c);
                  NSLog(@"(5) %d", !!b == !!c);
                  NSLog(@"(6) %d", (b != 0) == (c != 0));
                  

                  结果:

                  (1) 0
                  (2) 0
                  (3) 1
                  (4) 1
                  (5) 1
                  (6) 1
                  

                  推荐答案

                  在 Objective-C 中使用 bool 是完全有效的,因为它是 C99 标准的一部分(第 7.16 节).在我看来,这也是处理布尔类型安全比较的最佳方式.

                  It's perfectly valid to use bool in Objective-C as it's part of the C99 standard (§7.16). In my opinion it's also the best way to handle safe comparisons of boolean types.

                  不到处使用 bool 的唯一原因是 BOOL 在 Objective-C 和框架中无处不在.

                  The only reason not to use bool everywhere is that BOOL is omnipresent in Objective-C and the frameworks.

                  这篇关于在 Objective-c 中,比较 2 个 BOOL 值的安全和好方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Objective C 布尔数组 下一篇:如何在 Swift 的布尔数组中找到多个 True 语句

                  相关文章

                  1. <small id='iIwq6'></small><noframes id='iIwq6'>

                    <tfoot id='iIwq6'></tfoot>
                    • <bdo id='iIwq6'></bdo><ul id='iIwq6'></ul>
                    1. <i id='iIwq6'><tr id='iIwq6'><dt id='iIwq6'><q id='iIwq6'><span id='iIwq6'><b id='iIwq6'><form id='iIwq6'><ins id='iIwq6'></ins><ul id='iIwq6'></ul><sub id='iIwq6'></sub></form><legend id='iIwq6'></legend><bdo id='iIwq6'><pre id='iIwq6'><center id='iIwq6'></center></pre></bdo></b><th id='iIwq6'></th></span></q></dt></tr></i><div id='iIwq6'><tfoot id='iIwq6'></tfoot><dl id='iIwq6'><fieldset id='iIwq6'></fieldset></dl></div>
                      <legend id='iIwq6'><style id='iIwq6'><dir id='iIwq6'><q id='iIwq6'></q></dir></style></legend>