iphone – 在Objective-C中的正式和非正式协议有什么区别?

iphone – 在Objective-C中的正式和非正式协议有什么区别?,第1张

概述Objective-C中的正式和非正式协议有什么区别? 从 Official Documentation Formal and Informal Protocols There are two varieties of protocol, formal and informal: An informal protocol is a category on NSObject, which impli Objective-C中的正式和非正式协议有什么区别?解决方法 从 Official Documentation

Formal and Informal Protocols

There are two varIEtIEs of protocol,
formal and informal:

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.

A formal protocol declares a List of methods that clIEnt classes
are expected to implement. Formal
protocols have their own declaration,
adoption,and type-checking Syntax.
You can designate methods whose
implementation is required or optional
with the @required and @optional
keywords. Subclasses inherit formal
protocols adopted by their ancestors.
A formal protocol can also adopt other
protocols.

Formal protocols are an extension to the Objective-C language.

总结

以上是内存溢出为你收集整理的iphone – 在Objective-C中的正式和非正式协议有什么区别?全部内容,希望文章能够帮你解决iphone – 在Objective-C中的正式和非正式协议有什么区别?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1045884.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-24
下一篇 2022-05-24

发表评论

登录后才能评论

评论列表(0条)

保存