On Sat, Mar 13, 2010 at 12:22 PM, David Chisnall
<address@hidden> wrote:
Hi Stef,
I believe you are missing something important here. Although some CoreFoundation types are not toll-free bridged with specific Objective-C classes, they are all __attribute__((NSObject)) and all implement (at least some of) the NSObject protocol. You can send -retain / -release to all of them, including things like CFSocket that are not toll-free bridged:
$ cat cf.m
#import <Cocoa/Cocoa.h>
#import <CoreFoundation/CoreFoundation.h>
int main(void)
{
CFSocketRef s = CFSocketCreate(NULL, 0, 0, 0, 0, 0, 0);
printf("%d\n", (int)CFGetRetainCount(s));
[(id)s retain];
printf("%d\n", (int)CFGetRetainCount(s));
printf("%d\n", (int)[(id)s retainCount]);
NSLog(@"%@", s);
NSLog(@"%@", [(id)s class]);
return 0;
}
Liberator:tmp theraven$ gcc -framework Cocoa cf.m && ./a.out
2
3
3
2010-03-13 18:20:07.933 a.out[44021:903] <CFSocket 0x100111290 [0x7fff704fbf20]>{valid = Yes, type = 1, socket = 3, socket set count = 0,
callback types = 0x0, callout = ??? (0x0), source = 0x0,
run loops = <CFArray 0x100111360 [0x7fff704fbf20]>{type = mutable-small, count = 0, values = ()},
context = <CFSocket context 0x0>}
2010-03-13 18:20:07.978 a.out[44021:903] __NSCFType
As you can see, the object responds to -retainCount, -retain, -description and -class. It will also respond to things like -hash - you can store all CoreFoundation types in Objective-C collection classes (they are also Core Foundation collection types) transparently, for example.
David