iOS - 在 Swift 中,我们是否“发送消息"?或“调用方法/函数"? [英] iOS - In Swift, do we "send a message" or "call method/function"?

查看:61
本文介绍了iOS - 在 Swift 中,我们是否“发送消息"?或“调用方法/函数"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Swift 是在编译时保留方法查找列表还是在特定内存位置调用函数?

Does Swift keep the the method lookup list when compiled or does it call a function in a specific memory location?

最好的问候.

关于这个:http://davedelong.tumblr.com/post/58428190187/an-observation-on-objective-c

推荐答案

我建议您查看以下链接,尤其是第一个链接,因为它通过 C++ 和 Objective-C 的示例解释了概念,以便更好地理解静态、延迟和动态调度之间的区别(对于方法).

I would recommend you have a look at the below links, especially the first one because it explains the concepts with examples from C++ and Objective-C, in order to have a better understanding of the difference between static, late and dynamic dispatch (for methods).

简而言之:

函数及其实现是在编译时确定的,因此不会在运行时失败(因为除非绑定成功,否则编译器不会继续编译过程).

The function and its implementation is determined at compile time and thus can’t fail at runtime (because the compiler will not continue the compilation process unless the binding is successful).

函数是在编译时确定的,但实际的实现取决于运行时对象的类型.对继承很重要.编译器将检查类或其任何父类是否声明了该函数,但由运行时来选择要使用的实现.后期绑定可以像 C++ 一样使用虚拟表来实现.

The function is determined at compile time, but the actual implementation depends on the type of the object at runtime. Important for inheritance. The compiler will check if the the class or any of its parents have the function declared, but its up to the runtime to choose which implementation to use. The late binding can be implemented using virtual tables like in the case of C++.

函数是在运行时确定的,在Objective-C的情况下可以通过名称调用,因此如果接收器(对象)没有实现或继承可以响应指定消息的方法,则可能会在运行时失败.

The function is determined at runtime, which in the case of Objective-C can be called by name and thus can fail at runtime if the receiver (object) doesn't implement or inherit a method that can respond to a specified message.

这篇关于iOS - 在 Swift 中,我们是否“发送消息"?或“调用方法/函数"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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