Reputation: 19
I am currently having issues converting NSString
to a const void *
Here is my code:
DoSomethingFunction:(const void *)parameter
[class DoSomeThingFunction:(const void *)passswordField.text]
Password field is a UITextfield
. The value becomes null when I try and cast it.
I want passwordField.text
to be a const void *
so it can be used in the function.
Upvotes: 0
Views: 1683
Reputation: 3145
It depends on function implementation. It can be like this:
NSString *string = @"text";
const void *parameter = CFBridgingRetain(string);
DoSomethingFunction(parameter);
If function has similar parameter handling
void DoSomethingFunction(const void *parameter) {
NSString *string = CFBridgingRelease(parameter);
NSLog(@"%@", string);
}
Upvotes: 1
Reputation: 8147
Try casting the result of one of the NSString's methods that return a C string:
– cStringUsingEncoding:
– getCString:maxLength:encoding:
– UTF8String
Upvotes: 0