如何解决这个错误?实例方法'-attributesOfItemAtPath:error:'not found(返回类型默认为'id')

时间:2013-05-09 05:40:54

标签: objective-c macos compiler-errors

我在头文件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。但我无法理解这个错误。请帮帮我。

1 个答案:

答案 0 :(得分:1)

您错过了输入错误。

 error:&error];