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]) {
In a method fileExistsAtPath:isDirectory:
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.
Using:
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