我想知道女巫是测试 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/