Nick VanderPyle
Nick VanderPyle

Reputation: 2999

Cast "const void *" to "const char *"

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:

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

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

Upvotes: 3

Views: 8094

Answers (2)

dreamlax
dreamlax

Reputation: 95355

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];

Upvotes: 3

duncanwilcox
duncanwilcox

Reputation: 3498

Just like you would in C:

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

should work.

Upvotes: 5

Related Questions