Objective-C Runtime
A lot of programming languages is ship with a kind of runtime/standard library
which includes some core/base functionality
Objective-C Runtime
is responsible for dynamism, memory management(allocation, reference counting...) and other language features. It is a layer between compiler and core libraries/frameworks
.
Objective-C is dynamic
language because shift focus from compile time
to runtime
:
- Dynamic typing - figure out object's class in runtime. inheritance and other OOP principles
- Dynamic binding - figure out invoked method in runtime.
Message dispatch mechanism
[About]
- Dynamic loading - you are able to lazy-loading a new module in runtime.
Other features:
- basic structures like class, object, variable, property, method
- functions for working with these structures
- Introspection - get/read info about class/object in runtime. For example instance variables, methods names, method arguments. class_getName
- Reflection - modify its own structure and behavior. For example allocate new class, add variable, add method. class_addMethod
- objc_msgSend - based on message dispatch
- Swizzling - swap method realisation in runtime. method_exchangeImplementations. [Objective C], [Swift] swizzling example
Using [@objc vs dynamic
] expose Swift's API for Objective-C and adds a dynamic behaviour for Swift code. It is useful when you need something which is not possible to do with usual swift approaches. Good examples are KVO, swizzling...
[KVO]
Objective-C vs Swift
Swift
can use Objective-C Runtime
library.
Swift has better performance(based on table dispatch) but Objective-C is more dynamic language