-1

Here is my code:

NSString *string    = @"Ciyt";
const char *City    = [CityString UTF8String];
CFStringRef value   = CFSTR(&City);

show following error at third row in Xocde:

Invalid operands to binary expression ( 'char *' and 'char *' );

Any idea to resolve it?

NoNaMe
  • 6,020
  • 30
  • 82
  • 110
Stoull
  • 1,098
  • 8
  • 13

2 Answers2

1

CFSTR is a macro that only works with string literals, like CFSTR ("abc").

gnasher729
  • 51,477
  • 5
  • 75
  • 98
  • YES, I find the CFSTR description in apple document : Creates an immutable string from a constant compile-time string. CFStringRef CFSTR ( const char *cStr ); cStr A constant C string (that is, text enclosed in double-quotation marks) from which the string is to be created. – Stoull Sep 02 '15 at 08:31
0

I'm not 100% sure what you're trying to achieve here, but if you want to convert an NSString into a CFString you can do this directly without going via a C string thanks to toll-free bridging:

NSString *string = @"Ciyt";
CFStringRef value = CFBridgingRetain(string);

// use value...

CFBridgingRelease(value);

Here's a screenshot of the Variables View showing the result:

enter image description here

Steve Wilford
  • 8,894
  • 5
  • 42
  • 66
  • thanks, Steve Wilford. I just try to use CFSTR and a C string instead CFSTR and text enclosed in double-quotation marks to create a CFString, but it doesn't work – Stoull Sep 02 '15 at 08:31
  • Why are you even trying to use `CFSTR` though? If you want a `CFString` use the method I have described. – Steve Wilford Sep 02 '15 at 08:45