zoukankan      html  css  js  c++  java
  • swift与oc的关系

    swift是对oc的扩展

    Swift是没有消息机制的Objective-C

    https://www.oschina.net/translate/inside-swift;

    swift保持了oc的类结构形式,对函数的派发机制做了调整。

    一、class

    swift完全继承了oc class类的运行时结构;

    或者说swift class 和 oc class的运行时结构具有等价性;

    swift的编译器将class的缺省运行机制编译为静态派发和虚函数表派发;

    添加特殊@objec符号后,使用的是oc运行的动态派发机制;

    因为具有相同的运行时结构,所以能够相互调用。

    二、内存管理

    Class Layout

    Swift relies on the following assumptions about the Objective-C runtime, which are therefore now part of the Objective-C ABI:

    • 32-bit platforms never have tagged pointers. ObjC pointer types are either nil or an object pointer.
    • On x86-64, a tagged pointer either sets the lowest bit of the pointer or the highest bit of the pointer. Therefore, both of these bits are zero if and only if the value is not a tagged pointer.
    • On ARM64, a tagged pointer always sets the highest bit of the pointer.
    • 32-bit platforms never perform any isa masking. object_getClass is always equivalent to *(Class*)object.
    • 64-bit platforms perform isa masking only if the runtime exports a symbol uintptr_t objc_debug_isa_class_mask;. If this symbol is exported, object_getClass on a non-tagged pointer is always equivalent to (Class)(objc_debug_isa_class_mask & *(uintptr_t*)object).
    • The superclass field of a class object is always stored immediately after the isa field. Its value is either nil or a pointer to the class object for the superclass; it never has other bits set.

    The following assumptions are part of the Swift ABI:

    • Swift class pointers are never tagged pointers.

    https://github.com/apple/swift/blob/master/docs/ABI/TypeLayout.rst

    三、其他类型

    struct、enum、protocol

    四、其他范式

    范型、函数式编程

    参考文献:

    https://www.cnblogs.com/feng9exe/p/10573772.html

     

  • 相关阅读:
    [哀悼雅安芦山地震]把网页由彩色变成灰度(谷歌、火狐、ie等浏览器兼容)
    hdu 3367 Pseudoforest(最大生成树)
    解决MDK4以上版本没法对STM32软件仿真
    [置顶] java高级工程师struts的内部运行机制详解
    hdu 2141 二分搜索
    windows调试器之Visual C++
    2013年4月19日佳都新太笔试题+解答
    一步步理解Linux进程(3)内核中进程的实现
    什么是你的核心竞争力之一?
    ubuntu创建桌面启动器
  • 原文地址:https://www.cnblogs.com/feng9exe/p/11225009.html
Copyright © 2011-2022 走看看