Boolean pointer initialization warning

I am getting a new warning about initializing a pointer of type "BOOL *" (aka 'bool *') to null from a constant boolean expression. Is this the code that triggers a warning I haven't seen before?

if ([[NSFileManager defaultManager]fileExistsAtPath:filePath isDirectory:NO]) {



source to share

1 answer

In a method fileExistsAtPath:isDirectory:


, this is returned by a reference parameter, that is, it returns a Bool indicating whether the path is a directory or not.

From Apple docs:

isDirectory: Returned YES if the path is a directory or the last element of the path is a symbolic link pointing to a directory, NO otherwise. If the path does not exist, it is undefined when returned. Pass NULL if you don't need this information.


BOOL isDirectory;
if ([[NSFileManager defaultManager]fileExistsAtPath:filePath isDirectory:& isDirectory]) {
    if (isDirectory) {
        // Code for the directory case
    else {
        // Code for the file case


If you don't want to know if the directory path is:

- (BOOL)fileExistsAtPath:(NSString *)path




All Articles