Clang LLVM 1.0 错误 Objective-c
我是一名初级开发人员。我停止了这个错误:
Clang LLVM 1.0 Error
Expected ':'
line: [pipe fileHandleForReading availableData]
有人可以帮助我吗?提前致谢。
- (NSInteger)sizeOfItemAtPath:(NSString*)path {
BOOL isdir;
[[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:&isdir];
if (isdir) {
NSPipe *pipe = [NSPipe pipe];
NSTask *t = [[[NSTask alloc] init] autorelease];
[t setLaunchPath:@"/usr/bin/du"];
[t setArguments:[NSArray arrayWithObjects:@"-k", @"-d", @"0", path, nil]];
[t setStandardOutput:pipe];
[t setStandardError:[NSPipe pipe]];
[t launch];
[t waitUntilExit];
NSString *sizeString = [[[NSString alloc] initWithData:[[pipe fileHandleForReading availableData] encoding:NSASCIIStringEncoding] autorelease];
sizeString = [[sizeString componentsSeparatedByString:@" "] objectAtIndex:0];
BOOL bytes;
bytes = [sizeString longLongValue]*1024;
}
else {
BOOL bytes;
bytes = [[[NSFileManager defaultManager] attributesOfItemAtPath:path error:nil] fileSize];
}
BOOL bytes;
return bytes;
}
I'm a beginner developer. I'and stopped with this error about:
Clang LLVM 1.0 Error
Expected ':'
line: [pipe fileHandleForReading availableData]
Can anyone help me? Thanks in advance.
- (NSInteger)sizeOfItemAtPath:(NSString*)path {
BOOL isdir;
[[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:&isdir];
if (isdir) {
NSPipe *pipe = [NSPipe pipe];
NSTask *t = [[[NSTask alloc] init] autorelease];
[t setLaunchPath:@"/usr/bin/du"];
[t setArguments:[NSArray arrayWithObjects:@"-k", @"-d", @"0", path, nil]];
[t setStandardOutput:pipe];
[t setStandardError:[NSPipe pipe]];
[t launch];
[t waitUntilExit];
NSString *sizeString = [[[NSString alloc] initWithData:[[pipe fileHandleForReading availableData] encoding:NSASCIIStringEncoding] autorelease];
sizeString = [[sizeString componentsSeparatedByString:@" "] objectAtIndex:0];
BOOL bytes;
bytes = [sizeString longLongValue]*1024;
}
else {
BOOL bytes;
bytes = [[[NSFileManager defaultManager] attributesOfItemAtPath:path error:nil] fileSize];
}
BOOL bytes;
return bytes;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您缺少
]
:它必须是整行需要如下所示:
另外,您的方法将返回垃圾。这是因为您已经定义了
bytes
三次:一次在if
分支中,一次在else
分支中,一次在封闭的方法主体中。返回值将从最后一个获取,但这个已初始化。不仅如此,您还使用了错误的类型:它必须是NSInteger bytes;
,而不是BOOL bytes;
。您需要将定义放在方法的开头并删除所有其他定义,该变量可能只存在一次。You are missing a
]
: it must beThe whole line needs to look like this:
Also, your method will return garbage. That is because you've defined
bytes
three times: once in theif
branch, once in theelse
branch and once in the enclosing method body. The return value will be taken from the last one, but this one is initialized. Not only that, but you're using the wrong type: it must be aNSInteger bytes;
, notBOOL bytes;
. You need to put the definition at the start of the method and remove all other definitions, the variable may exist only once.试试这个:
Try this: