The relationship swift and oc

swift is oc extension

Swift no message mechanism Objective-C

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

 

swift to maintain the structure of oc class, mechanism of distribution function made adjustments.

 

A, class

fully inherited the swift run oc class when the class structure;

Structure or equivalent with swift class operation and when oc class;

 

The default operation of the compiler compiler swift mechanism of static class virtual function table distribution and distribution;

After @objec add special symbols, using a dynamic dispatch mechanism oc running;

 

Because the same run-time configuration, it is possible to call each other.

 

Second, memory management

 

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

 

Third, other types

struct、enum、protocol

 

 

Fourth, other paradigms

Paradigm, functional programming

 

references:

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

 

Guess you like

Origin www.cnblogs.com/feng9exe/p/11225009.html