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 回答