@objc vs @objc dynamic

@objc:  Objective-C entry points

One can explicitly write @objc on any Swift declaration that can be expressed in Objective-C.

@objc dynamic:入口+动态派发机制。using the Objective-C message send mechanism。

dynamic no longer infers @objc

A declaration that is dynamic will no longer infer @objc. For example:

 

This change is intended to separate current implementation limitations from future language evolution: the current implementation supports dynamic by always using the Objective-C message send mechanism, allowing replacement of dynamic implementations via the Objective-C runtime (e.g., class_addMethod and class_replaceMethod). In the future, it is plausible that the Swift language and runtime will evolve to support dynamic without relying on the Objective-C runtime, and it's important that we leave the door open for that language evolution.

This change therefore does two things. First, it makes it clear that the dynamic behavior is tied to the Objective-C runtime. Second, it means that well-formed Swift 4 code will continue to work in the same way should Swift gain the ability to provide dynamic without relying on Objective-C: at that point, the method foo() above will become well-formed, and the method bar() will continue to work as it does today through the Objective-C runtime. Indeed, this change is the right way forward even if Swift never supports dynamic in its own runtime, following the precedent of SE-0070, which required the Objective-C-only protocol feature "optional requirements" to be explicitly marked with @objc.

https://github.com/apple/swift-evolution/blob/master/proposals/0160-objc-inference.md

备注:

@objc exposes the variable to the ObjC runtime. dynamic tells the runtime to use dynamic dispatch instead of the default static dispatch. dynamic also implies @objc so @objc dynamic is redundant. You mostly utilize them in KVO and Cocoa Binding

https://stackoverflow.com/questions/48559768/what-does-objc-dynamic-var-mean-in-swift-4

最新文章

  1. hdu5714 拍照[2016百度之星复赛C题]
  2. python中的二维数组和lamda
  3. JustMock Lite (Free Mocking Framework For .net)
  4. 类中用const限定的成员函数
  5. sql_action
  6. maven安装仓库中不存在的jar包
  7. ios警告:Category is implementing a method which will also be implemented by its primary class 引发的相关处理
  8. 使用 Spring 3 来创建 RESTful Web Services(转)
  9. U盘启动格式
  10. HTTP真的很简单(转)
  11. Python强大的自省简析
  12. iOS开发——NSArray中的字典排序
  13. C# 使用SmtpClient发送Email
  14. 第二次作业-熟悉git
  15. MySQL ProxySQL相关维护说明
  16. tensorflow 调试tfdbg
  17. 在windows 下使用eclipse进行编译和烧写
  18. 20145206邹京儒Exp6 信息搜集与漏洞扫描
  19. Maven编译Java程序配置
  20. Java调用WeChat's API总结

热门文章

  1. Nginx——静态资源服务器(一)
  2. Navicat 提示Cannot create oci environment 解决方案
  3. vim插件:显示树形目录插件NERDTree安装 和 使用【转】
  4. caioj1275&&hdu4035: 概率期望值6:迷宫
  5. POJ1733 Parity game —— 种类并查集
  6. ubuntu下nginx的安裝
  7. openssl动态库编译
  8. [转]POI读写Excel 修改
  9. Java 抽象类和接口的理解
  10. Java语法基础练习2