を比較するファイルは、それのサイズを変更した場合、私は(私の場合、私はタイマーを選んだ)ループを確認したいです。 は、私は次のようにしますそうするには、次のNSStringのは、私は、現在のMac OS Xに</p> <p>を比較する文字列に苦しんだNSTimer「ループ」に
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
fileSize = [[NSString stringWithFormat:@""] retain];
fileSizeSrc = [[NSString stringWithFormat:@""] retain];
fileManager = [NSFileManager defaultManager];
fileAtts = [fileManager attributesOfItemAtPath:@"~/Desktop/test.txt" error:NULL];
fileSizeSrc = [NSString stringWithFormat:@"%llu", [fileAtts fileSize]];
[self startWatching:nil];
}
- (void)startWatching:(id)sender
{
timer = [NSTimer scheduledTimerWithTimeInterval:2
target:self
selector:@selector(checkForUpdates)
userInfo:nil
repeats:YES];
[timer fire];
}
- (void)checkForUpdates
{
fileAtts = [fileManager attributesOfItemAtPath:@"~/Desktop/test.txt" error:NULL];
fileSize = [NSString stringWithFormat:@"%llu", [fileAtts fileSize]];
if([fileSize isEqualToString:fileSizeSrc])
{
NSLog(@"%@", fileSize);
fileSizeSrc = [NSString stringWithFormat:@"%@", fileSizeSrc];
}
}
- (void)applicationWillTerminate:(NSNotification *)notification
{
[timer invalidate];
timer = nil;
[fileSize release];
[fileSizeSrc release];
}
私はちょうどのサイズを一度に確認することができます。 私のコードの実行時(セレクタが二度目の発射があったとき)だから、それは私のプログラムがEXC_BAD_ACCESS
で終了し、私はif(![fileSize isEqualToString:fileSizeSrc])
に変更している場合()文を反転しようとすると、後で私に出力し、2秒を与えます起動直後に終了します。
問題が最初に発生した後、私はそれが私に起こったので、私はこれをしなければならないので、文字列を保持してから解放しました。
誰かが私を助けてくれることを願っています! ありがとう、 Greets、Julian。