so i've spent the day struggling with CFDictionary... it's not as easy as NSDictinary too...
i think i've put stuff into the dictionary:
(that's not the actual name of the key, i just did that so you know i'm using a string)
so, i'm trying to store a number into this dictionary with a key.
i think i've done this right, it's basically copy pasted from example code from Apple...
the problem now is... i can't get the value out of it.
i tried what i thought was correct:
but it turns out that value is null and doesn't exist...uh... didn't i put in the same key as i used to add the value?
i tried numerous other ways too.
i tried using this:
this time value exists, but any attempt to do anything with it results in a runtime error that isn't caught by try-catch
i've tried a few other ways too, but always i either get something that doesn't exist (as with the first example), or something that just causes an uncatchable error (as with the second example)
i read that you can cast a CFDictionary to NSDictionary, so i tried:
no compiler warning or errors but it came with runtime errors that you'd expect if you tried to cast something to something else that it cant cast too...
anyone know the proper way to do this?
i think i've put stuff into the dictionary:
Code:
CFStringRef key = CFSTR("ChironesKey");
NSString* val = [NSString stringWithFormat: @"%d", [aNumber intValue]];
CFStringEncoding encoding = kCFStringEncodingMacRoman;
const char *cstr_hello = [val UTF8String];
CFAllocatorRef alloc_default = kCFAllocatorDefault;
CFStringRef value = CFStringCreateWithCString(alloc_default, cstr_hello, encoding);
CFDictionaryRef info = CFDictionaryCreate(kCFAllocatorDefault, (const void **)key, (const void**)value, 2, NULL, NULL);
so, i'm trying to store a number into this dictionary with a key.
i think i've done this right, it's basically copy pasted from example code from Apple...
the problem now is... i can't get the value out of it.
i tried what i thought was correct:
Code:
CFStringRef key = CFSTR("VQLineIndex");
const void* value = CFDictionaryGetValue(userInfo,key);
i tried numerous other ways too.
i tried using this:
Code:
CFTypeRef* values;
int size = CFDictionaryGetCount(userInfo);
values = (CFTypeRef *) malloc( size * sizeof(CFTypeRef) );
CFDictionaryGetKeysAndValues(userInfo, NULL, (const void **) values);
const char* value = (const char*)values[0];
i've tried a few other ways too, but always i either get something that doesn't exist (as with the first example), or something that just causes an uncatchable error (as with the second example)
i read that you can cast a CFDictionary to NSDictionary, so i tried:
Code:
NSDictionary* val = (NSDictionary*)userInfo
anyone know the proper way to do this?