Objective-C在自定义方法中将NSError指针传递给NSFileManager
我有一个方法使用ARC并获取一个N错误指针,然后将其传递到Objective-C在自定义方法中将NSError指针传递给NSFileManager,objective-c,pointers,nsfilemanager,nserror,Objective C,Pointers,Nsfilemanager,Nserror,我有一个方法使用ARC并获取一个N错误指针,然后将其传递到目录下的目录路径:error:方法NSFileManager中,如下所示: + (NSArray *) getContentsOfCurrentDirectoryWithError: (NSError **)error { // code here _contentsOfCurrentDirectory = [_fileManager contentsOfDirectoryAtPath: _documentDirecto
目录下的目录路径:error:
方法NSFileManager
中,如下所示:
+ (NSArray *) getContentsOfCurrentDirectoryWithError: (NSError **)error
{
// code here
_contentsOfCurrentDirectory = [_fileManager contentsOfDirectoryAtPath: _documentDirectory error: error];
// more code here
}
我不确定这段代码是否正确,因为我不太习惯指针,因为它被托管语言破坏了。然而,我最初的反应是这样做:
_contentsOfCurrentDirectory = [_fileManager contentsOfDirectoryAtPath: _documentDirectory error: &error];
不过,Xcode对我这样尝试大喊大叫。我的假设是,contentsOfDirectoryAtPath:error:
方法要求一个指针,因为我在getContentsOfCurrentDirectoryWithError:error:
方法中要求一个指针,所以我只需传递error
,而不使用取消引用操作符
我只是想确保我这样做是正确的,以避免以后的麻烦,那么我所拥有的有问题吗?方法可以类似于.h文件中的NSError**errorMessage:
+ (NSArray *) getContentsOfCurrentDirectory
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *_documentsDirectory = [paths objectAtIndex:0];
NSArray *_contentsOfCurrentDirectory = [[NSFileManager defaultManger] contentsOfDirectoryAtPath: _documentDirectory error: errorMessage];
return contentsOfCurrentDirectory ;
}
每当发生错误时,errorMessage引用都会有错误消息[error description]好吧,我本来打算让我的自定义方法能够公开内部方法可能遇到的任何错误。