Clang LLVM 1.0 错误 Objective-c

发布于 2024-12-11 13:43:26 字数 1186 浏览 4 评论 0原文

我是一名初级开发人员。我停止了这个错误:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

2024-12-18 13:43:26

您缺少 ]:它必须是

[[pipe fileHandleForReading] availableData]

整行需要如下所示:

NSString *sizeString = [[[NSString alloc] initWithData:[[pipe fileHandleForReading] availableData] encoding:NSASCIIStringEncoding] autorelease];

另外,您的方法将返回垃圾。这是因为您已经定义了 bytes 三次:一次在 if 分支中,一次在 else 分支中,一次在封闭的方法主体中。返回值将从最后一个获取,但这个已初始化。不仅如此,您还使用了错误的类型:它必须是 NSInteger bytes;,而不是 BOOL bytes;。您需要将定义放在方法的开头并删除所有其他定义,该变量可能只存在一次。

You are missing a ]: it must be

[[pipe fileHandleForReading] availableData]

The whole line needs to look like this:

NSString *sizeString = [[[NSString alloc] initWithData:[[pipe fileHandleForReading] availableData] encoding:NSASCIIStringEncoding] autorelease];

Also, your method will return garbage. That is because you've defined bytes three times: once in the if branch, once in the else 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 a NSInteger bytes;, not BOOL bytes;. You need to put the definition at the start of the method and remove all other definitions, the variable may exist only once.

我爱人 2024-12-18 13:43:26

试试这个:

[[pipe fileHandleForReading] availableData]

Try this:

[[pipe fileHandleForReading] availableData]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文