不兼容的整数到指针转换

时间:2013-07-11 07:28:14

标签: objective-c

我正在检查目录是否存在,但我收到警告

  

不兼容的整数到指针转换发送'BOOL'(又名'签名'   char')到'BOOL *'类型的参数(又名'signed char *')

 BOOL isFile ;
 isFile = [[NSFileManager defaultManager] fileExistsAtPath:[dirurl path] isDirectory:YES];

为什么我会收到此警告以及如何解决此问题

1 个答案:

答案 0 :(得分:9)

像这样使用:

BOOL isDir;
BOOL isFileExists;

isFileExists = [[NSFileManager defaultManager] fileExistsAtPath:[dirurl path] isDirectory:&isDir];
if (isDir) {...}

官方文档示例developer.apple.com

NSArray *subpaths;
BOOL isDir;

NSArray *paths = NSSearchPathForDirectoriesInDomains
                     (NSLibraryDirectory, NSUserDomainMask, YES);

if ([paths count] == 1) {

    NSFileManager *fileManager = [[NSFileManager alloc] init];
    NSString *fontPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"Fonts"];

    if ([fileManager fileExistsAtPath:fontPath isDirectory:&isDir] && isDir) {
        subpaths = [fileManager subpathsAtPath:fontPath];
// ...
[fileManager release];