Currenlty I have an issue with ocmock for unit testing because some @dynamic properties have no getters or setters when being mocked. I'm using class_addmethod
to add the getters and setters for all @dynamic properties. My issue is this
void accessorSetter(id self, SEL _cmd, id newValue)
{
NSString *method = NSStringFromSelector(_cmd);
id value = [newValue copy];
// remove set prefix from string
NSString *anID = [[method stringByReplacingCharactersInRange:NSMakeRange(0, 3) withString:@""] stringByReplacingOccurrencesOfString:@":" withString:@""];
anID = [anID stringByReplacingCharactersInRange:NSMakeRange(0,1) withString:[[anID substringWithRange:NSMakeRange(0, 1)] lowercaseString]];
[self setValue:value forKey:anID];
}
causes an infite loops since setValue calls the setter. I think I can use c++ syntax like self->somevar = value
to avoid the infinite loop. My question is how do I do this assigment when the name of the variable is a string? anID is the name of the variable and i can't do self->anID = aValue
cuz anID is not a property. How do I convert it to a variable name? Or how can I set the property without creating the infinite loop?