objective-c: double pointers to property not allowed?

前端 未结 5 2178
独厮守ぢ
独厮守ぢ 2020-12-15 05:42

I want to create a method like this:

- (void) checkAndUpdateStringProperty: (NSString **) property{
   if (...) 
      *property = @\"whatever\";
}
         


        
5条回答
  •  渐次进展
    2020-12-15 06:01

    There are very few places in the Apple APIs that a value is passed in this fashion, the main one being NSError. It is really best to just return the result. If you do have a reference parameter the general Apple rule is that it should be the last parameter that that the method name begin with "get" as in getCheckAndUpdateStringProperty.

    But you can do it, it is just not what we are used to.

    The error you are seeing is that self.productName is really shorthand for the method call: [self productName] so &self.productName is interpreted as &[self productName].

    Further in this case if productName is a @property with a retain attribute the reference counting will be subverted.

提交回复
热议问题