Context: I have several CGPathRef in a custom class derived from NSObject with a name model. I am looking for a way to return a specific CGPathRef based on the string that I generate at runtime.
A simplified example if I can use KVC:
#model.h
@property (nonatomic) CGMutablePathRef pathForwardTo1;
@property (nonatomic) CGMutablePathRef pathForwardTo2;
@property (nonatomic) CGMutablePathRef pathForwardTo3;
...
#someVC.m
-(void)animateFromOrigin:(int)origin toDestination:(int)destination{
int difference = abs(origin - destination);
for (int x =1; x<difference; x++) {
NSString *pathName = [NSString stringWithFormat:@"pathForwardTo%d", x];
id cgPathRefFromString = [self.model valueForKey:pathName];
CGPathAddPath(animationPath, NULL, cgPathRefFromString);
}
}
Question: How can I access properties that are not compatible with KVC (CGPathRef), only with their name represented as a string?
source
share