I have a C type pointer variable:
a_c_type *cTypePointer = [self getCTypeValue];
How can I convert cTypePointer to NSObject type & vise versa?
Should I use NSValue? What is the proper way to do so with NSValue?
I have a C type pointer variable:
a_c_type *cTypePointer = [self getCTypeValue];
How can I convert cTypePointer to NSObject type & vise versa?
Should I use NSValue? What is the proper way to do so with NSValue?
On
You simply use the method valueWithPointer: to wrap a pointer value as an NSValue object, and pointerValue to extract the pointer value.
These are just like valueWithInt:/intValue et al - they wrap the primitive value. You are not wrapping what the pointer points at. Therefore it is important that you ensure that when extract the pointer that whatever it pointed at is still around, or else the pointer value will be invalid.
Finally you must cast the extract pointer value, which is returned as a void *, back to be its original type, e.g. a_c_type * in your example.
(If you want to wrap what is being pointed at consider NSData.)
HTH
You can indeed use a NSValue.
note that the 1st parameter is a pointer (void*). the object will contain the pointed value.
to get back to C:
Note that you would get the actual value, not the pointer. But then, you can just
Test it :
test with ptr :