首页 > 其他 > 详细

Object-C中的非正式协议与正式协议

时间:2016-01-04 19:47:05      阅读:127      评论:0      收藏:0      [点我收藏+]

  之前对 "非正式协议"一词不甚理解,查阅一番后就自己的理解简单梳理一下,

  下面是苹果官方文档Cocoa Core Competencies一文中对非正式协议的介绍:

  An informal protocol is a category on NSObject, which implicitly makes almost all objects adopters of the protocol. (A category is a language feature that enables you to add methods to a class without subclassing it.) Implementation of the methods in an informal protocol is optional. Before invoking a method, the calling object checks to see whether the target object implements it. Until optional protocol methods were introduced in Objective-C 2.0, informal protocols were essential to the way Foundation and AppKit classes implemented delegation.

  可见非正式协议就是我们常用的类别(Category),而正式协议就是一个以@protocol方式命名的方法列表,与非正式协议相比不同的是,它要求显示的遵守协议。

Object-C中的非正式协议与正式协议

原文:http://www.cnblogs.com/moyazi/p/5099920.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!