Delegation and Core Location(Chapter 4 of iOS Programming: The Big Nerd Ranch Guide)

Delegation is an object-oriented approach to callbacks. A callback is a function that is supplied in advance of an event and is called every time the event occurs. Some objects need to make a callback for more than one event. For instance, the location manager wants to “callback” when it finds a new location and when it encounters an error.
However, there is no built-in way for two (or more) callback functions to coordinate and share information. This is the problem addressed by delegation – we supply a single delegate to receive all of the event messages for a particular object. This delegate object can then store, manipulate, act on, and relay the related information as it sees fit.
Before sending an optional method, the object first asks its delegate by sending another message, respondsToSelector:. Every object implements this method, which checks at runtime whether an object implements a given method. 
To avoid retain cycles, delegate properties use the assign attribute instead of retain or copy. We call this a “weak reference,” where an object has a pointer to another object but does not retain it. 

转载于:https://www.cnblogs.com/zhtf2014/archive/2011/11/01/2231091.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值