zoukankan      html  css  js  c++  java
  • swift @objc dynamic

    @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

  • 相关阅读:
    docker使用
    解决wps linux中文字体名字全是英文
    解决小程序云函数操作数据库回调不执行
    解决XP“不是有效Win32程序” 不是改Platform toolset
    [hdu1686] Oulipo【KMP】
    [poj 2104] K-th Number【主席树】
    bzoj2806 [Apio2012]dispatching【可并堆】
    bzoj1492 [NOI2007]货币兑换Cash【cdq分治】
    [coci2015-2016 coii] torrent【树形dp 二分】
    [coci2015-2016 coii] Palinilap【字符串 哈希】
  • 原文地址:https://www.cnblogs.com/feng9exe/p/9676051.html
Copyright © 2011-2022 走看看