What's the Point of (NSError**)error?

后端 未结 6 1095
小蘑菇
小蘑菇 2020-12-16 20:33

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

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

Since

6条回答
  •  南方客
    南方客 (楼主)
    2020-12-16 20:55

    It is what some people refer to as an "out" parameter.

    You're not passing a pointer to an NSError object, you're passing a pointer to a local variable. This gives the called method the ability to modify your local variable; in this case, to assign it to an NSError instance.

    Perhaps what's confusing is that the local variable you're passing to save: is itself a pointer, so the variable type ends up being a pointer to a pointer.

    Bottom line, it's a pointer to a local variable, and it works the same whether the local variable is an int or an NSError*.

提交回复
热议问题