私はfileeventapiを使用してフォルダーを監視するデスクトップアプリケーションに取り組んでいるので、基本的にこれは私のコードです:
#import "PNAppDelegate.h"
void callback(
ConstFSEventStreamRef streamRef,
void *clientCallBackInfo,
size_t numEvents,
void *eventPaths,
const FSEventStreamEventFlags eventFlags[],
const FSEventStreamEventId eventIds[])
{
[(__bridge PNAppDelegate *)clientCallBackInfo reloadStatus];
};
@implementation PNAppDelegate
@synthesize window = _window;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSArray *pathsToWatch = [NSArray arrayWithObject: @"/Users/romainpouclet/Projects/foo"];
void *appPointer = (__bridge void *)self;
FSEventStreamContext context = {0, appPointer, NULL, NULL, NULL};
FSEventStreamRef stream;
CFAbsoluteTime latency = 3.0;
stream = FSEventStreamCreate(NULL,
&callback,
&context,
(__bridge CFArrayRef) pathsToWatch,
kFSEventStreamEventIdSinceNow,
latency,
kFSEventStreamCreateFlagNone);
NSLog(@"Schedule with run loop");
FSEventStreamScheduleWithRunLoop(stream, CFRunLoopGetMain(), kCFRunLoopDefaultMode);
FSEventStreamStart(stream);
[self reloadStatus];
}
-(void)reloadStatus
{
}
@end
問題ありません。これと同じくらい単純なPOCの場合はかなりうまく機能しますが、少し醜い感じがします(おそらく、Objective-CとCの混合にはあまり慣れていません)。だからここに私の質問があります:
- コールバックはどこで宣言すればよいですか?それがそこで機能したという理由だけで、私のファイルの先頭にそれがあるのは奇妙に感じます。
- コールバックの代わりに、ある種の@selectorベースのアプローチを使用することは可能ですか?(私は彼らが安心していると思います:D)
御時間ありがとうございます !