objective-c: double pointers to property not allowed?

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

    I'd do this using the selectors instead (you'll have to convert it to a c function to get it to work without warning (see here):

    - (void) checkAndUpdateStringProperty: (SEL)setter {
       if (...) 
         IMP imp = [self methodForSelector:setter];
         void (*func)(id, SEL, id) = (void *)imp;
         func(self, setter, @"whatever");
    }
    

    Use this to pass in the selector for the same class:

    - (void) somewhereElse{
           ....
           [self checkAndUpdateStringProperty:@selector(setProductName:)];
    }
    

提交回复
热议问题