質問

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.

役に立ちましたか?

解決 2

Try casting the result of one of the NSString's methods that return a C string:

– cStringUsingEncoding:
– getCString:maxLength:encoding:
– UTF8String

NSString Class Reference

他のヒント

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);
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top