gpt4 book ai didi

ios - NSRunLoop API 区别

转载 作者:可可西里 更新时间:2023-11-01 05:36:08 26 4
gpt4 key购买 nike

NSRunLoop 有两个 api:

- (BOOL)runMode:(NSString *)mode beforeDate:(NSDate *)limitDate

- (void)acceptInputForMode:(NSString *)mode beforeDate:(NSDate *)limitDate

我的意思是除了返回值之外它们是相同的,还是有其他区别?

最佳答案

正如@DarkDust 所暗示的,它曾经与计时器有关。参见 Chris Kane's discussions on the Cocoa mailing list .在某一时刻,runMode:beforeDate:limitDateForMode:acceptInputForMode:beforeDate: 的包装(因为 acceptInputForMode:beforeDate: 没有触发计时器)。我对文档、 header 和崩溃堆栈的阅读表明,如今它们的行为相同(调用 CFRunLoopRunInMode(),它会触发计时器)。但我还没有构建测试应用程序来确认。

如果您阅读原文NeXT ObjC manual , acceptInputForMode:beforeDate: 用于明确不触发计时器:

Blocks awaiting input from the ports in the port list for the input mode mode until the time specified by limitDate. Use the limitDateForMode: method to calculate limitDate. If input arrives, it is processed using the NSPort delegates. This method does not check the timers associated with mode, thus it does not fire timers even if their scheduled fire dates have passed.

计时器被显式处理为 limitDateForMode: 的副作用

Polls mode's input sources for their limit date (if any) and returns the earliest limit date for this mode. Uses the NSPort delegate method limitDateForMode: to determine the limit dates of ports. Fires timers if their limit dates have passed. Polls ports for activities appropriate for mode. Returns nil if there are no input sources for this mode.

这就是为方便起见添加 runMode:beforeDate: 的原因(参见 NSRunloop.h):

@interface NSRunLoop (NSRunLoopConveniences)

- (void)run;
- (void)runUntilDate:(NSDate *)limitDate;
- (BOOL)runMode:(NSString *)mode beforeDate:(NSDate *)limitDate;

#if (TARGET_OS_MAC && !(TARGET_OS_EMBEDDED || TARGET_OS_IPHONE))
- (void)configureAsServer NS_DEPRECATED(10_0, 10_5, 2_0, 2_0);
#endif

另见 NeXT:

The method limitDateForMode: returns the earliest limit date of all the input sources for the mode NSDefaultRunLoopMode. acceptInputForMode:beforeDate: runs the loop until that date, processing any input it receives until that time. As a convenience, you can use runMode:beforeDate: instead. It invokes acceptInputForMode:beforeDate: and limitDateForMode: with the mode you supply.

所以简短的回答:历史。

关于ios - NSRunLoop API 区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18210901/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com