可以转发属性吗?
可以转让房产吗?
假设我有一个代理类,它有一个成员,而该成员又具有一个名为 string
的属性。
我希望我的代理类具有相同的属性,也名为 string
。从那里开始,我希望每当我在代理上调用 getter/setter 时,它都会在其类成员上设置/获取值。
我最接近的是实现 -forwardingTargetForSelector
并在需要时切换目标,但它不干净也不实用(它会发出警告,并且您不能使用点语法)
Is it possible to forward a property?
Let's say I have a proxy class that has a member which has in turns a property called string
.
I want my proxy class to have the same property also named string
. From there, I would like that whenever I call the getter/setter on the proxy, it set/get value on its class member.
the closest I have come to it is to implement -forwardingTargetForSelector
and switch the target when needed but it's not clean nor pratical (it gives warning and you cannot use the dot-syntax)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将属性声明为
@dynamic
并实现这两个方法来处理转发 -methodSignatureForSelector:
和forwardInspiration:
。实施将如下所述 -You can declare the properties as
@dynamic
and implement these two methods to handle the forwarding -methodSignatureForSelector:
andforwardInvocation:
. Implementation will be something has described below –