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;
}
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
bytesthree times: once in theifbranch, once in theelsebranch 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.