objective-c: double pointers to property not allowed?

前端 未结 5 2149
独厮守ぢ
独厮守ぢ 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:02

    If you are really careful about the ownership attributes, you can get around this issue by staring at the following:

    [self property]
    

    vs:

    self.property
    

    vs:

    self->property
    

    Once you are clear about the difference you can try this:

    [self checkAndUpdateStringProperty: &self->productName]
    

    Note the use of: ->

    I use this all the time when the property attribute is assign and when it is a primitive, non object type: (float, int, ...)

提交回复
热议问题