CFStringRef createCFStringFor4CC (CFStringRef fourCCString) {
UInt32 errorCode = CFStringGetIntValue(fourCCString);
errorCode = CFSwapInt32HostToBig (errorCode);
return CFStringCreateWithFormat (
kCFAllocatorDefault, NULL,
(CFStringRef) @"%4.4s", (char*)&errorCode);
}
- (NSString*) stringFor4CC: (NSString*) fourCCString {
UInt32 errorCode = [fourCCString intValue];
errorCode = CFSwapInt32HostToBig (errorCode);
return [NSString stringWithFormat: @"%4.4s", (char*)&errorCode];
}
The Obj-C version returns an autoreleased string, but the C version you'll have to CFRelease() when you're done with it.
The need to do an endian flip kind of surprised me. I guess I would have expected that a definition like:
would have maintained the same byte order from the header to the iPhone Simulator or device. Or maybe it does and I'm just not thinking through where each char ends up when it's stored as a UInt32?