class_getName 函数文档
<https://developer.apple.com/library/prerelease/watchos/documentation/Cocoa/Reference/ObjCRuntimeRef/#//apple_ref/c/func/class_getName>
说的是:
> The name of the class, or the empty string if cls is Nil.
这一句 ”the empty string if cls is Nil“ 不对。
实际上不是字符串 "nil"
查看了最新开源的代码 ,也确实返回的是 "nil"
```objc
const char *class_getName(Class cls)
{
if (!cls) return "nil";
assert(cls->isRealized() || cls->isFuture());
return cls->demangledName();
}
```
最近想到的一个学习 Objective-C Runtime 的学习方式就是为 其 API 编写测试简单的测试用例。
如 `class_getName`
```objc
- (void)test_class_getName{
XCTAssert(strcmp("Demo", class_getName([Demo class])) == 0);
const char * actual = class_getName(nil);
XCTAssert(strcmp("nil", actual) == 0);
}
```
<https://developer.apple.com/library/prerelease/watchos/documentation/Cocoa/Reference/ObjCRuntimeRef/#//apple_ref/c/func/class_getName>
说的是:
> The name of the class, or the empty string if cls is Nil.
这一句 ”the empty string if cls is Nil“ 不对。
实际上不是字符串 "nil"
查看了最新开源的代码 ,也确实返回的是 "nil"
```objc
const char *class_getName(Class cls)
{
if (!cls) return "nil";
assert(cls->isRealized() || cls->isFuture());
return cls->demangledName();
}
```
最近想到的一个学习 Objective-C Runtime 的学习方式就是为 其 API 编写测试简单的测试用例。
如 `class_getName`
```objc
- (void)test_class_getName{
XCTAssert(strcmp("Demo", class_getName([Demo class])) == 0);
const char * actual = class_getName(nil);
XCTAssert(strcmp("nil", actual) == 0);
}
```