如何使 BOOL 在短时间内具有值,然后在 Objective-C 中更改
我有一个在 if 语句中使用的 Bool 。该变量一开始为 NO,然后我输入 if 语句,如果 bool 值为 NO,则该语句执行。然后我在 if 语句末尾将值更改为 YES,这样它就不会再次执行,标准的东西。
我想要做的是在最后以某种方式更改该变量“是”,但在大约五秒后将其更改回“否”。那怎么办呢?
I have a Bool that I am using in an if statement. The variable starts out as NO, then I enter the if statement, which executes if the bool's value is NO. Then I change the value to YES at the end of the if statement so it won't execute again, standard stuff.
What I want to do is somehow change that variable YES at the end, but have it change back to NO after about five seconds. How can that be done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
NSTimer
:另外,请确保此属性 (
someBoolean
) 是atomic
。You can use
NSTimer
:Also, make sure that this property (
someBoolean
) isatomic
.也许设置类似:
添加类似的内容
并向您的班级 。但是你确定你需要这样做吗 - 听起来很容易获得竞争条件。
谢谢,
Dw。
Perhaps set something like:
and add something like
to your class. But are you sure you need to do this - sounds easy to get a race condition.
Thanks,
Dw.