为什么 NSDictionary 报告一个不寻常的类名? [英] Why does NSDictionary report an unusual class name?
本文介绍了为什么 NSDictionary 报告一个不寻常的类名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
NSDictionary *dict = [NSDictionary dictionary];
NSLog(@"%@", NSStringFromClass([dict class]));
此代码打印__NSDictionary0".
This code prints "__NSDictionary0".
对于我自己的类,它打印实际的类名.
For my own classes it prints the actual class name.
为什么将 NSDictionary 标识为 __NSDictionary0,依赖它是否安全?
Why is NSDictionary identified as __NSDictionary0, and is it safe to depend on this?
推荐答案
NSDictionary 是一个类簇.在此处阅读有关它们的信息:
NSDictionary is a class cluster. Read about them here:
由于实际"类本身是私有的,不,依赖它不安全.
As the "actual" class itself is private, no, it is not safe to depend on this.
如果你需要知道你的类是否真的是一个 NSDictionary,使用 [dict isKindOfClass:[NSDictionary class]];
If you need to know if your class is really an NSDictionary or not, use [dict isKindOfClass:[NSDictionary class]];
这篇关于为什么 NSDictionary 报告一个不寻常的类名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文