开发者

When to retain a "delegate"

I know that in Objective-C you should never retain your delegates because it may cause a retain-cycle, howeve开发者_StackOverflow中文版r, 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 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.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜