As I know in Objective-C all classes are inherit from NSObject class. What about Swift? For what purposes we need to inherit from NSObject in Swift?
Asked
Active
Viewed 1,616 times
1 Answers
5
Nothing about the Swift language inherently requires you to inherit from NSObject. There is no Swift base class. NSObject is not part of Swift. In the absence of Cocoa Foundation, NSObject doesn't even exist as far as Swift is concerned.
In practical usage — e.g., when programming iOS — the reason you might want a class to inherit from NSObject would have to do with Cocoa, not Swift; it would be because you want Objective-C to be able to work with that class in some special way that is only possible if this is an NSObject subclass.

matt
- 515,959
- 87
- 875
- 1,141