I have a method that uses ARC and takes an NSError pointer and I pass that into the contentsOfDirectoryAtPath:error:
method of NSFileManager
like so:
+ (NSArray *) getContentsOfCurrentDirectoryWithError: (NSError **)error
{
// code here
_contentsOfCurrentDirectory = [_fileManager contentsOfDirectoryAtPath: _documentDirectory error: error];
// more code here
}
I'm not sure if this code is correct, because I'm not very used to pointers due to being spoiled by managed languages. However, my initial reaction was to do this:
_contentsOfCurrentDirectory = [_fileManager contentsOfDirectoryAtPath: _documentDirectory error: &error];
Xcode yelled at me for trying it like that, though. My assumption as to how this might work is that the contentsOfDirectoryAtPath:error:
method is asking for a pointer and, since I was asking for a pointer in my getContentsOfCurrentDirectoryWithError:error:
method, I can just pass error
without using the dereference operator.
I just want to make sure I'm doing this right to avoid hassle later, so is there a problem with what I have?