Sometimes I need to implement proxy pattern in ObjC. I need it in cases were I create inner subject in runtime and do not want to move creation logic out from the proxy. Sometimes I use couple of objects inside the proxy, also I prefer use ARC to memory menegment. Now I implement it using C++ style:
- (void)setProperty:(CGFloat)value
{
_innerObject.value = value;
}
- (CGFloat)property
{
return _innerObject.value;
}
<...>
I think that it is not a best way, I think that exist more easy way. I want to use ObjC runtime and forward messages automatically.
How I can do it without write every set/get method by hand?
- forwardingTargetForSelector:
"[r]eturns the object to which unrecognized messages should first be directed". So:
// Will be queried for every message that is sent to `self` but
// which `self` does not itself implement.
- (id)forwardingTargetForSelector:(SEL)selector
{
return _innerObject;
}