码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2016-01-04 19:49:31      阅读:121      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!