问题描述
我正在研究Swift中的面向对象编程,我发现一个很好的起点是NSObject
,因为所有对象都继承自该基类.在 Apple的NSObject
文档,其中某些区域涉及接收者". 接收器"是否表示NSObject
的实例?
I'm researching Object-Oriented Programming in Swift and I figured a great place to start would be NSObject
, since all objects inherit from this base class. In Apple's documentation for NSObject
, there are areas that refer to a "receiver". Does "receiver" mean an instance of NSObject
?
推荐答案
它是指Objective-c的向对象发送消息"的范例.在那个世界中,方法"并不是真正的方法,只是对象在说:嘿,如果有人向我发送此消息(与该方法名称匹配的字符串),我会响应."即该对象是消息的接收者".所以是的,在您提到的文档中,NSObject是接收者,您看到的方法中有消息".
It refers to Objective-c's paradigm of "sending messages" to objects. In that world, a "method" isn't REALLY a method, it's just the object saying, "Hey, if someone sends me this message (a string that matches that method name), I'll respond to it." i.e. that object is the "receiver" for the message. So yes, in the documentation you mention, NSObject is the receiver and the methods you see there are the "messages".
这篇关于在Apple的NSObject文档中,“接收器"的概念是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!