将“const void *”转换为“const char *”

时间:2022-05-01 21:40:18

I have code like this:

我有这样的代码:

NSData *data = [NSData dataWithContentsOfURL:objURL];
const void *buffer = [data bytes];
[self _loadData:buffer];
[data release];

the "_loadData" function takes an argument like:

“_loadData”函数接受如下参数:

- (void)_loadData:(const char *)data;

How do I convert "const void " to a "const char" on Objective-C?

如何将“const void”转换为Objective-C中的“const char”?

2 个解决方案

#1


5  

Just like you would in C:

就像你在C中写的那样:

[self _loadData:(const char *)buffer];

should work.

应该工作。

#2


3  

You mustn't release the data object because you did not explicitly allocate it. Also, you could do a simple cast:

您不能释放数据对象,因为您没有显式地分配它。同样,你也可以做一个简单的石膏模型:

[self _loadData:(const char *) buffer];

#1


5  

Just like you would in C:

就像你在C中写的那样:

[self _loadData:(const char *)buffer];

should work.

应该工作。

#2


3  

You mustn't release the data object because you did not explicitly allocate it. Also, you could do a simple cast:

您不能释放数据对象,因为您没有显式地分配它。同样,你也可以做一个简单的石膏模型:

[self _loadData:(const char *) buffer];