何时保留“代表"身份? [英] When to retain a "delegate"

查看:60
本文介绍了何时保留“代表"身份?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道在Objective-C中您永远不要保留委托,因为这可能会导致保留周期,但是,您如何知道委托与非委托对象之间的区别呢?不能说仅向任何对象发送消息就是将工作委派给该对象吗?

I know that in Objective-C you should never retain your delegates because it may cause a retain-cycle, however, how do you know the difference between a delegate and a non-delegate object ? Can't it be said that just sending a message to any object is delegating work to that object ?

推荐答案

A

A delegate in Objective-C has a fairly well established definition. They're typically used in classes that are already implemented, but have some options for customization.

例如, UIApplicationDelegate 用于实现特定于应用程序的行为,因此您不必将UIApplication子类化.这有助于最小化样板代码.

For example, the UIApplicationDelegate is used to implement application specific behavior so that you don't have to subclass UIApplication. This helps to minimize boilerplate code.

此外,通常使用委托属性保留委托对象.我会争辩说,不是委托属性的任何对象都不是委托对象.委托对象通常用于代表常规对象起作用.

Also, delegate objects are usually kept around using the delegate property. I would argue that any object that isn't the delegate property, isn't a delegate object. The delegate objects are usually used to act on behalf of the regular object.

我希望这会有所帮助,您的问题是开放性的.

I hope this helps, your question was quite open-ended.

这篇关于何时保留“代表"身份?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆