How to monitor a folder for new files in swift?

前端 未结 10 2130
既然无缘
既然无缘 2020-12-23 17:17

How would I monitor a folder for new files in swift, without polling (which is very inefficient)? I\'ve heard of APIs such as kqueue and FSEvents - but I\'m not sure it\'s p

10条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-23 17:50

    Depending on your application needs, you may be able to use a simple solution.

    I actually used kqueue in a production product; I wasn't crazy with the performance but it worked, so I didn't think too much of it till I found a nice little trick that worked even better for my needs, plus, it used less resources which can be important for performance intensive programs.

    What you can do, again, if your project permits, is that every time you switch to your application, you can just check the folder as part of your logic, instead of having to periodically check the folder using kqueue. This works and uses far less resources.

提交回复
热议问题