I am trying to write a bit of Objective-C (which is new for me, my background is more C++), and wanted to create a CFString like this :
CFString myString;
When I try to build my project the following error :
"'CFString' undeclared" (first use in this function)
prevents from building.
I thought I had just forgot to include the relevant header, but I cannot find which one to include. When I look into some sample code I never see “CFString” but rather “CFStringRef” objects, defined as
A reference to a CFString object.
typedef const struct __CFString *CFStringRef;
I started to suspect there is no such thing as a CFString that i can refer to in the code, but I feel I am wrong somewhere. Am I ?
Is it impossible to create CFStrings ? Is it specific to CFString or to all the structs in objective-c ?
CFStringRefis part of the Core Foundation library which is not ObjC but plain C. Core Foundation uses a runtime to create instances, this runtime will call callbacks to initialize the structs content and manages the instances memory.This is why there is no
CFStringbecause you shouldn’t create static instances on the stack but rather call the appropriate create function which will then ask the runtime for a new instance with everything already initialized for you. ForCFStringRefthis would beCFStringCreate(), see also: http://developer.apple.com/library/ios/#documentation/CoreFoundation/Conceptual/CFStrings/introCFStrings.html