在 Apple 的 NSObject 文档中,“接收器"的概念是什么? [英] In Apple's Documentation for NSObject, what is the idea of the "receiver"?

查看:74
本文介绍了在 Apple 的 NSObject 文档中,“接收器"的概念是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究 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 文档中,“接收器"的概念是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆