objective-c - 如何测试 *void 指针是否指向 Objective C 中的 NSObject

标签 objective-c testing nsobject void-pointers

我想知道女巫是测试 void 指针是否实际上是一个 Objective-C 对象指针 (NSObject*) 的最佳实践...

- (id)initWithExecPath:(NSString*)executePath withArgs:(NSArray*)args identifier:(NSString*)identifierString contextInfo:(void*)contextInfo {

// I would like to check here if contextInfo is an NSObject

}

谢谢...

最佳答案

查看来自 CocoaWithLove 的这篇帖子网站:

In this post, I look at an approach for testing if an arbitrary pointer is a pointer to a valid Objective-C object. The result from the test is not absolutely accurate and can interfere with gdb debugging if the pointer isn't a valid memory location, so this is not something you'd want to do often (and certainly not in production code). But it can be a handy debugging tool for when you're staring blindly at memory you didn't allocate.

关于objective-c - 如何测试 *void 指针是否指向 Objective C 中的 NSObject,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8677416/

相关文章:

iphone - 如何在 UIButton 中从正常状态和选定状态下的标题文本设置 UIImage

objective-c - 为自定义单元格设置 uitableviewcell 高度

ios - 如何将持有 int 的 iOS id 类型转换为 NSString?

ios - 存储自定义类 iOS 8 核心数据

ios - 从 NSObject 类创建数组

ios - setImageWithURLRequest 加载成功但显示相同的图像

objective-c - 如何隐藏 AVFoundation 调试日志?

c# - 如何使用 WebApplicationFactory 播种测试数据?

java - 如何在带注释的 UIThreadTest 方法中说 waitForIdleSync()

python - 使用常规 python 脚本运行 Nose 测试