【问题标题】:Clang LLVM 1.0 Error objective-cClang LLVM 1.0 错误目标-c
【发布时间】:2011-10-23 10:53:50
【问题描述】:

我是一名初学者。我停止了这个错误:

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;
}

【问题讨论】:

    标签: objective-c macos nsstring


    【解决方案1】:

    你错过了]:它一定是

    [[pipe fileHandleForReading] availableData]
    

    整行应该是这样的:

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

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

    【讨论】:

      【解决方案2】:

      试试这个:

      [[pipe fileHandleForReading] availableData]
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-06-17
        • 1970-01-01
        • 1970-01-01
        • 2012-04-20
        • 2014-10-01
        相关资源
        最近更新 更多