本文介绍了什么是(NSError **)错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

示例: NSSagedObjectContext -save:方法声明如下:

Example: The -save: method of NSManagedObjectContext is declared like this:

- (BOOL)save:(NSError **)error

由于NSError已经是一个类,并且传递一个指针实际上会在 -save:的实现中修改这个对象的效果,那是什么将指针传递给指针的重点是什么?什么是优势/意义?

Since NSError is already a class, and passing a pointer would actually have the effect of modifying this object inside the implementation of -save:, what's the point of passing a pointer to a pointer here? What's the advantage/sense?

用法示例:

NSError *error;
if (![managedObjectContext save:&error]) {
    // Handle the error.
}


推荐答案

如果你刚刚通过指针,所有方法都可以改变你指向的已经存在的NSError对象。

If you just passed in a pointer, all the method could do would alter the already existing NSError object that you are pointing to.

通过传入一个指向指针的指针,它可以创建新的NSError对象并留下指向它们的指针。

By passing in a pointer to a pointer, it can create new NSError objects and leave you with a pointer that points to them.

这篇关于什么是(NSError **)错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 09:11