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.
本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
上一篇:MapKit and Text Input(Chapter 5 of iOS Programming: The Big Nerd Ranch Guide)
下一篇:Memory Management(Chapter 3 of iOS Programming: The Big Nerd Ranch Guide)
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
Core Image Programming Guide Part2
Create,
sed ico ide lua scala