用NSValue封装C或C++的对象(结构…

来源:互联网 发布:淘宝差评多长时间生效 编辑:程序博客网 时间:2024/05/16 11:08
假设存在对象:
class testClass
{
public:
string myCode;
}

封装示范代码:
testClass* test = new testClass();
test.myCode = "Hello NSValue";
NSValue* value = [NSValue valueWithBytes:(voide*)testobjcType:@encode(testClass)];
return value;

解封示范代码:
testClass* testRecive = new testClass();
[value getValue:testRecive];
printf("%s",testRecive.myCode.c_str());

用途:
用来把C/C++的对象(结构体)封装成objC的对象NSValue,便于在objC调用,以及使用NSArray、NSDictonary等数据结构传递。

0 0
原创粉丝点击