0

ヘッダー KTLog.h で関数を宣言します。

 - (NSString *)logfileName;

そして、これを KTLog.m のように実装します。

- (NSString *)logfileName
 {
    NSString *logPath = [[NSString stringWithFormat:@"%@", NSHomeDirectory()]            stringByAppendingPathComponent:@"Library/Logs/"];
NSFileManager *fm = [NSFileManager defaultManager];
BOOL isDir;

if (!([fm fileExistsAtPath:logPath isDirectory:&isDir] && isDir))
{
     NSURL *nsrulLogpath = [NSURL URLWithString:logPath];
    if (![fm createDirectoryAtURL:nsrulLogpath withIntermediateDirectories:nil attributes:nil error:nil])
    {
        NSLog(@"Failed to create log directory: %@", logPath);
    }
}

NSString *processName = [[NSProcessInfo processInfo] processName];
NSString *logName = [logPath stringByAppendingPathComponent:[NSString    stringWithFormat:@"%@.ktlog", processName]];

 if (![fm fileExistsAtPath:logName])
 {
    if (![fm createFileAtPath:logName contents:[NSData data] attributes:nil])
    {
        NSLog(@"Failed to create log file at: %@", logName);
    }
}

return logName;

}

しかし、この関数をこのように呼び出すと、

  NSDictionary *logAttribs = [[NSFileManager defaultManager] attributesOfItemAtPath:[self logfileName] eror:&error];

エラーが発生しました。KTLog.m ファイルに KTLog.h をインポートします。しかし、私はこのエラーを理解できませんでした。私を助けてください。

4

1 に答える 1

1

入力エラーを見逃しています。

 error:&error];
于 2013-05-09T05:43:45.507 に答える