core-foundation

How to determine if currency symbol is to the left or right of a number on MacOS

How do I determine if the currency symbol is supposed to be on the left or right of a number using CFLocale / CFNumberFormatter in a Mac Carbon project? I need to interface with a spreadsheet application which requires me to pass a number, currency symbol, currency symbol location and padding instead of a CStringRef created with CFNumbe...

Converting plist to binary plist

Apple strongly recommends using the binary plist format when reading large XML-based data sets into iPhone apps. Among their reasoning is the fact that XML parsing is very taxing on the iPhone. However, this requires that files residing on the remote web server be converted first. For frequently-changing content, it is not acceptable to...

Is there a method to generate a standard 128bit GUID (UUID) on the Mac?

Is there a built in function equivalent to .NET's Guid.NewGuid(); in Cocoa? My desire is to produce a string along the lines of 550e8400-e29b-41d4-a716-446655440000 which represents a unique identifier. ...

Getting raw HTTP request from CFHTTPMessageRef

I am working with a wrapper class for CFHTTPMessage, which contains a CFHTTPMessageRef object to which is added the method (GET), the URL of the web application server, and a few custom headers containing the date and an authentication nonce. I'm having some problems getting the method and URL to return certain data. I think I've worked...

CFReadStreamHasBytesAvailable polling - best practices

I'm currently polling my CFReadStream for new data with CFReadStreamHasBytesAvailable. (First, some background: I'm doing my own threading and I don't want/need to mess with runloop stuff, so the client callback stuff doesn't really apply here). My question is: what are accepted practices for polling? Apple's documentation on the subj...

What does the 'k' prefix indicate in Apple's APIs?

I've run across many examples of Core Foundation variables named k + someVariableNameHere or k + APILibraryName(2Char) + someVariableNameHere. What does this prefix K indicate? Examples include: kGLPFAStereo kCollectionLockBit kSetDebugOption ...

Get a calculated length of a Core Foundation string given an encoding

Is there a way to get the length in bytes of a CFString given an arbitrary character encoding? It seems possible because the function CFStringGetSmallestEncoding must do some calculations already, but I don't want to use the smallest encoding, I want to find out how big a buffer I might need to allocate if I want the bytes in UTF-8 encod...

NSURLConnection delegate doesn't get its didReceiveAuthenticationChallenge method on server status 401

I've setup a simple NSURLConnection to query an http-server. GET /path HTTP/1.1 Host: 192.168.1.161:8282 User-Agent: NetTest1.0 CFNetwork/441.0.2 Darwin/9.6.0 Accept: */* Accept-Language: en-us Accept-Encoding: gzip, deflate Pragma: no-cache Connection: keep-alive The server responds with code 401 and the WWW-Authenticate header set ...

How to get the token type from a CFStringTokenizer in Cocoa?

The CFStringTokenizer documentation has two conflicting statements in CFStringTokenizerAdvanceToNextToken(): CFStringTokenizerAdvanceToNextToken ... Return Value The type of the token if the tokenizer succeeded in finding a token and setting it as current token. Returns kCFStringTokenizerTokenNone if the tokenizer fail...

Releasing Core Foundation object references

Do I need to release a Core Foundation objects to clear up memory? And if so, how? For example, in the code: ABAddressBookRef addressBook = ABAddressBookCreate(); CFArrayRef peopleArray = ABAddressBookCopyArrayOfAllPeople(addressBook); do I need to release peopleArray? What about addressBook? ...

CFNetwork HTTP timeout?

I am looking for a way to add a timeout to a CFHTTP request. It seems like there should be a feature of the CFHTTPMessage or the CFReadStream object, but I can't find it. Do I have to roll my own timer on the run loop or something? (if so, any code for this?) Thanks! ...

In Cocoa, how do I set the TTL on a packet?

I want to be able to explicitly set the TTL value for a socket connection using Cocoa. I've been unable to see anything useful in the CoreFoundation docs. Do I need to go even lower to the BSD Sockets to set the TTL value? ...

Why would CFRelease(NULL) crash?

Is there a reason why CFRelease does not check for NULL? Isn't it unacceptable when [nil release]; free(NULL); delete NULL; all work perfectly fine? ...

Storing a C struct in CFMutableDictionary

Since there is no counterpart to NSValue in Core Foundation, how are we supposed to store C structs in a CFMutableDictionary? ...

Creating Core Foundation classes

Since I can't seem to find any documentation on this subject, is it possible to create your own Core Foundation "class"? (classes as in ones that can be used with CFRetain() and CFRelease) I want to take advantage of the polymorphic capabilities and object inspection built into Core Foundation without the overhead of Objective-C or creat...

Is there an integer vector struct in Cocoa or should I define my own?

I am keeping track of pairs of ints and NSUIntegers as array indexes and other things. Is there something analogous to CGPoint that is already defined? I'm doing graphics stuff on iPhone if it matters. ...

How to release memory created from CFStringTokenizerCreate?

I use CFRelease to release the CFStringTokenizerRef obtained from CFStringTokenizerCreate call. But instruments is reporting memory leak at around this area. Am I missing something? CFStringTokenizerRef tokenRef = CFStringTokenizerCreate(NULL, (CFStringRef)contents, ...

Difference between Foundation Framework and Core Foundation Framework?

I try to get the hang of it, but for now both seem the same thing to me. However, Xcode allows to create an Console App with choice of using "Core Foundation" or just "Foundation". Maybe someone can point out the differences. ...

Testing file existence using NSURL

Snow Leopard introduced many new methods to use NSURL objects to refer to files, not pathnames or Core Services' FSRefs. However, there's one task I can't find a URL-based method for: Testing whether a file exists. I'm looking for a URL-based version of -[NSFileManager fileExistsAtPath:]. Like that method, it should return YES if the UR...

Memory-mapped resource - or not?

Hi all, I'm trying to memory-map and use a largish binary data file from my iPhone bundle resources. I've added the "Resources should be file-mapped" line with a checkmark to my Info.plist. Then I'm getting the data block like this (error handling and data release omitted): CFBundleRef bun = CFBundleGetMainBundle(); CFURLRef url = CFBu...