Search code examples
swiftobjective-cruntimeterminologynsobject

What are objective c runtime features?


In a blog post I have just read:

'Swift allows us to extend classes from NSObject to get Objective-C runtime features for an object. It also allows us to annotate Swift methods with @objc to allow the methods to be used by the Objective-C runtime.'

I don't understand the term objective-C runtime features. Is it meaning that the code could be used in a objective-C project as well?


Solution

  • Quoting the apple docs

    The Objective-C runtime is a runtime library that provides support for the dynamic properties of the Objective-C language, and as such is linked to by all Objective-C apps. Objective-C runtime library support functions are implemented in the shared library found at /usr/lib/libobjc.A.dylib.

    That API is useful primarily for developing bridge layers between Objective-C and other languages, or for low-level debugging. You most likely don't need to use it.

    Even when written without a single line of Objective-C code, every Swift app executes inside the Objective-C runtime, so that's why you can access it.

    You can do things like swizzling