gpt4 book ai didi

objective-c - 不兼容的整数到指针的转换

转载 作者:太空狗 更新时间:2023-10-30 03:59:27 31 4
gpt4 key购买 nike

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

Incompatible integer to pointer conversion sending 'BOOL' (aka 'signed char') to parameter of type 'BOOL *' (aka 'signed char *')

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

为什么我会收到此警告以及如何修复它

最佳答案

像这样使用:

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

关于objective-c - 不兼容的整数到指针的转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17587468/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com