@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

swift @objc dynamic的更多相关文章

  1. @objc vs @objc dynamic官方解释

    Some Objective-C APIs—like target-action—accept method or property names as parameters, then use tho ...

  2. Swift & Objc 在同一个项目中的使用

    在WWDC大会中发布了Swift让人眼前一亮.终于加了很多的现代编程语言该有的东西.很早年以前玩C#3.0+的时候这些差不多类似的 已经用的烂熟的东西终于一点一点的在看Swift Programmin ...

  3. swift class的虚函数表、扩展、@objc修饰、虚函数的派发方式研究

    swift class的虚函数表.扩展.@objc修饰的研究 工具: swiftc -emit-sil BaseClass.swift | xcrun swift-demangle > Clas ...

  4. @objc and dynamic

      @objc and dynamic Objective-C runtime visibility and the depths of dynamic dispatch in the modern ...

  5. iOS开发系列--Swift进阶

    概述 上一篇文章<iOS开发系列--Swift语言>中对Swift的语法特点以及它和C.ObjC等其他语言的用法区别进行了介绍.当然,这只是Swift的入门基础,但是仅仅了解这些对于使用S ...

  6. IOS开发之SWIFT进阶部分

    概述 上一篇文章<iOS开发系列--Swift语言> 中对Swift的语法特点以及它和C.ObjC等其他语言的用法区别进行了介绍.当然,这只是Swift的入门基础,但是仅仅了解这些对于使用 ...

  7. Swift进阶

    概述 访问控制 Swift命名空间 Swift和ObjC互相调用 Swift和ObjC映射关系 Swift调用ObjC ObjC调用Swift 扩展—Swift调用C 反射 扩展—KVO 内存管理 循 ...

  8. 【自问自答】关于 Swift 的几个疑问

    感觉自己给自己释疑,也是一个极为有趣的过程.这次,我还新增了"猜想"一栏,来尝试回答一些暂时没有足够资料支撑的问题. Swift 版本是:4.0.3.不同版本的 Swift,可能无 ...

  9. realm swift调研--草稿

    realm swift调研: After you have added the object to the Realm you can continue using it, and all chang ...

随机推荐

  1. 注册中心Eureka页面添加用户认证

    我们需要登录即可访问到Eureka服务,这样其实是不安全的 为Eureka添加用户认证. 第一步,为itcast-microservice-eureka添加安全认证依赖: 第二步,增加applicat ...

  2. 《CMake实践》笔记一:PROJECT/MESSAGE/ADD_EXECUTABLE【转】

    本文转载自:http://www.cnblogs.com/52php/p/5681745.html 前言: 开发了5,6年的时间,如果没有KDE4,也许不会有人或者Linux发行版本重视cmake,因 ...

  3. HDU1160 FatMouse's Speed —— DP

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1160 FatMouse's Speed Time Limit: 2000/1000 MS ...

  4. 一.OC基础之:1,OC语言的前世今生 ,2,OC语言入门,3,OC语言与C的差异,4,面向对象,5,类和对象的抽象关系,6,类的代码创建,7,类的成员组成及访问

    1,OC语言的前世今生 , 一, 在20世纪80年代早期,布莱德.麦克(Brad Cox)设计了OC语言,它在C语言的基础上增加了一层,这意味着对C进行了扩展,从而创造出一门新的程序设计语言,支持对象 ...

  5. BZOJ 1305:dance跳舞(二分+最大流)

    一次舞会有n个男孩和n个女孩.每首曲子开始时,所有男孩和女孩恰好配成n对跳交谊舞.每个男孩都不会和同一个女孩跳两首(或更多)舞曲.有一些男孩女孩相互喜欢,而其他相互不喜欢(不会“单向喜欢”).每个男孩 ...

  6. BZOJ2874 训练士兵 主席树

    [啊 首先 这是道权限题,然后本人显然是没有权限的  23咳3] 最近数据结构做的越来越少..然后 就跟上次一样 ,一做就是三四种不同写法. 等价的题面: 最近GY大神在sc2的天梯中被神族虐得很惨, ...

  7. bzoj 4711 小奇挖矿 —— 树形DP

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4711 就是树形DP,然而也想了半天才把转移想清楚: f[x][j][0] 表示 x 去上面 ...

  8. Git学习三

    一.准备Github远程仓库 1.github官网注册账户 2.ubuntu端创建SSH Key $ssh-keygen -t rsa -C "youremail@example.com&q ...

  9. (DP)51NOD 1183 编辑距离

    编辑距离,又称Levenshtein距离(也叫做Edit Distance),是指两个字串之间,由一个转成另一个所需的最少编辑操作次数.许可的编辑操作包括将一个字符替换成另一个字符,插入一个字符,删除 ...

  10. SQL 实战教程(八)

    http://www.studyofnet.com/news/247.html 1.修改字段为自增 alter table [dbo].[Logs] drop column ID alter tabl ...