是否所有对象都继承自NSObject?

时间:2021-10-09 19:40:54

I know you can implement using Object class but is there any in Apple's Objective C?

我知道你可以使用Object类实现,但Apple的Objective C中有没有?

2 个解决方案

#1


10  

Just about every Cocoa class inherits from NSObject. Even the slightly esoteric Block objects, whose class tree isn't public, have NSObject at the root.

几乎每个Cocoa类都继承自NSObject。即使是稍微深奥的Block对象,其类树不是公共的,在根处也有NSObject。

The only other root class that is publicly known in Cocoa is NSProxy, though it does conform to the NSObject protocol, which allows it to act in many ways like any other Cocoa object.

Cocoa中唯一公知的其他根类是NSProxy,尽管它确实符合NSObject协议,它允许它像许多其他Cocoa对象一样以多种方式运行。

#2


1  

In theory, it is possible to define a class that does not inherit from NSObject.

理论上,可以定义一个不从NSObject继承的类。

But in practice it is so difficult that no-one ever bothers to do it. NSObject does quite a lot of very nice stuff for you.

但实际上很难让人无所事事。 NSObject为你做了很多非常好的事情。

#1


10  

Just about every Cocoa class inherits from NSObject. Even the slightly esoteric Block objects, whose class tree isn't public, have NSObject at the root.

几乎每个Cocoa类都继承自NSObject。即使是稍微深奥的Block对象,其类树不是公共的,在根处也有NSObject。

The only other root class that is publicly known in Cocoa is NSProxy, though it does conform to the NSObject protocol, which allows it to act in many ways like any other Cocoa object.

Cocoa中唯一公知的其他根类是NSProxy,尽管它确实符合NSObject协议,它允许它像许多其他Cocoa对象一样以多种方式运行。

#2


1  

In theory, it is possible to define a class that does not inherit from NSObject.

理论上,可以定义一个不从NSObject继承的类。

But in practice it is so difficult that no-one ever bothers to do it. NSObject does quite a lot of very nice stuff for you.

但实际上很难让人无所事事。 NSObject为你做了很多非常好的事情。