在继续[Obj-C]之前检查文件是否存在

时间:2022-04-02 20:53:30

currently here is my code

目前这是我的代码

NSFileManager *fileManager = [[NSFileManager alloc] init];

BOOL receiptExists = NO;
BOOL didLog = NO;

while (!receiptExists) {

    receiptExists = [fileManager fileExistsAtPath:PATH];

    if (!didLog) {
        NSLog(@"[NOTICE]: Waiting for the file to appear...\n");
        didLog = YES;
    }
}
// rest of the code

This while loop consumes a lot of resources and I'm sure there is a better obj-c implementation. Any thought ?

这个while循环消耗了大量资源,我确信有更好的obj-c实现。任何想法 ?

1 个解决方案

#1


5  

You can use the kqueue/kevent system, or FSEvents.

您可以使用kqueue / kevent系统或FSEvents。

Using this, you can be notified of changes, instead of polling for them.

使用此功能,您可以收到更改通知,而不是轮询它们。

If you'd like an Objective-C abstraction of these, you may want to try UKKQueue or SCEvent.

如果你想要这些的Objective-C抽象,你可能想尝试UKKQueue或SCEvent。

#1


5  

You can use the kqueue/kevent system, or FSEvents.

您可以使用kqueue / kevent系统或FSEvents。

Using this, you can be notified of changes, instead of polling for them.

使用此功能,您可以收到更改通知,而不是轮询它们。

If you'd like an Objective-C abstraction of these, you may want to try UKKQueue or SCEvent.

如果你想要这些的Objective-C抽象,你可能想尝试UKKQueue或SCEvent。