The documentation says
NOTE
Swift classes do not inherit from a universal base class. Classes you define without specifying a superclass
This is mainly a design decision, there are languages which have a root class (e.g. Java) and languages which don't (e.g. C++).
Note that in Obj-C a root class is not enforced. You can easily create an object which doesn't inherit from any class. You can also create your own root classes, there are at least 3 in the Apple API (NSObject
, NSProxy
and deprecated Object
).
The reason to have a root class is mostly historical - the root class ensures that all objects have some common interface, some common methods (e.g. isEqualTo:
, hash()
etc.) which are necessary for collection classes to work.
Once you have generics (or templates in C++), having a root class is not so important any more.
retain
and release
in NSObject
are not important anymore since ARC. With MRC, you were still required to call them. With ARC you never call the methods explicitly and they can be implemented more efficiently behind the scenes.
In Swift, the methods from NSObject
have been divided into protocols - Equatable
, Hashable
, Printable
and DebugPrintable
. That has the advantage that objects can share interfaces with structs.
However, there is nothing stopping you from inheriting every class from NSObject
. The class is still there and it is especially useful if you are dealing with Obj-C APIs. In pure Swift, a root class is not necessary though.
One more note:
Swift classes doesn't run on top of Obj-C; they are not translated into Obj-C behind the scenes. They are just compiled by the same compiler which allows them to interoperate with each other. That's really important to understand. That's why @objc
must be sometimes added to provide consistency with Obj-C protocols/classes.