5

Hello lovely computer people:

I would like to convert the following CFStringRef into a CString. Any idea how?

recordFilePath = (CFStringRef)[NSTemporaryDirectory() stringByAppendingPathComponent: @"recordedFile.wav"];

Thanks!


EDIT 1

DarkDust answer seems to come close, but I'm still getting an error (see comment). Any help?

Eric Brotto
  • 53,471
  • 32
  • 129
  • 174

2 Answers2

14

A straightforward solution:

CFStringGetCString(myCFStringRef, myCStringPointer, mySize, myEncoding);

Checkout this function:

Boolean CFStringGetCString (
   CFStringRef theString,
   char *buffer,
   CFIndex bufferSize,
   CFStringEncoding encoding
);
Vikram Singh
  • 1,726
  • 1
  • 13
  • 25
8

Since a CFStringRef can be toll-free casted to NSString, you can simply do:

myCString = [(NSString *)myCFStringRef UTF8String];

or in your case:

myCString = [[NSTemporaryDirectory() stringByAppendingPathComponent: @"recordedFile.wav"] UTF8String];
DarkDust
  • 90,870
  • 19
  • 190
  • 224