Objective-C - 在给定时间/日期执行功能
如何才能在给定的时间和日期调用一个函数?例如,我想在午夜存储某些变量的一些值(并将它们清除为零),以便可以将它们与前几天的值进行比较。
我如何在 Objective-C 中实现这一点?
谢谢,
杰克
How might one get a function to be called at given time and date? For example, I would like to store some values of some variables at midnight (and clear them to zero) so they can be compared with the previous days values.
How might I accomplish this in Objective-C?
Thanks,
Jack
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您有很多选择,具体取决于您的需求。
明显的起点是 NSTimer。
还有 performSelector withDelay 函数家庭。
最后,我有时会使用一个很酷的扩展,延迟块。
哦,还有一个 - 您还可以设置 Local通知。
You've got quite a few options, depending on what you're after.
The obvious place to start is NSTimer.
There's also the performSelector withDelay function family.
Lastly, a cool extension I sometimes use, delayed blocks.
Oh, one more - you can also setup Local Notifications.
使用 NSTimer 的 initWithFireDate:interval:target:selector:userInfo:repeats: 来设置您想要运行方法的时间。
Use NSTimer's
initWithFireDate:interval:target:selector:userInfo:repeats:
to set the time you want a method to be run.