core-foundation

Convert CFIndex to NSUInteger?

扶醉桌前 提交于 2019-12-11 02:04:50
问题 How do I convert typedef signed long CFIndex to typedef unsigned int NSUInteger ? Is it OK if I use a CFIndex as an argument of type NSUInteger . I haven't casted it, and the complier doesn't seem to mind. Does the compiler just do the conversion for me? 回答1: You need to be very careful here, since CFIndex is signed and NSUInteger is unsigned. There are various routines that return a CFIndex -1. You need to check for that before using it as an NSUInteger. 回答2: Yes, the compiler performs

How can I send a userInfo dict using CFNotificationCenterGetDarwinNotifyCenter()

风流意气都作罢 提交于 2019-12-10 20:05:48
问题 I need to send an object using CFNotificationCenterGetDarwinNotifyCenter() however, I'm noticing that whenever I send a notification using const void *tkeys[1] = { @"testKey" }; const void *tvalues[1] = { @"testValue" }; CFDictionaryRef userInfo = CFDictionaryCreate(NULL, tkeys, tvalues, 1, NULL, NULL); CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), CFSTR("foo"), object, userInfo, true); then I find that in the observer callback, the userInfo dict is NULL.

Do I need to manually release CFStringRef?

半世苍凉 提交于 2019-12-10 18:52:43
问题 Can you please tell me which is the right way and why in non ARC world. + (NSString *)getUUID { CFUUIDRef theUUID = CFUUIDCreate(NULL); CFStringRef string = CFUUIDCreateString(NULL, theUUID); CFRelease(theUUID); return [(NSString*) string autorelease]; } or + (NSString *)getUUID { CFUUIDRef theUUID = CFUUIDCreate(NULL); CFStringRef string = CFUUIDCreateString(NULL, theUUID); CFRelease(theUUID); return (NSString*)string; } 回答1: The other answers are correct for manual retain counting. When you

Message sent to deallocated instance with ARC using custom getter and setter

喜欢而已 提交于 2019-12-10 11:18:55
问题 I'm trying to implement a custom getter and setter for my custom object HFObject and my app crashed with a Message sent to deallocated instance error despite using ARC. I've read every single related post, the ones that were written pre-ARC don't apply, and everything else didn't help. I have the zombie object debugger option turned on. Setting up the custom HObject Within HObject.h I have declared these four properties: @property (retain) NSString *email; //Will use custom getter/setter

How to create a CFDictionary in an OS X target?

▼魔方 西西 提交于 2019-12-10 09:26:29
问题 According to documentation CFDictionaryCreate is used to instantiate CFDictionary in swift . func CFDictionaryCreate(_ allocator: CFAllocator!, _ keys: UnsafeMutablePointer<UnsafePointer<Void>>, _ values: UnsafeMutablePointer<UnsafePointer<Void>>, _ numValues: CFIndex, _ keyCallBacks: UnsafePointer<CFDictionaryKeyCallBacks>, _ valueCallBacks: UnsafePointer<CFDictionaryValueCallBacks>) -> CFDictionary! How can I create the keys and values arguments? So far I've tried to use swift's String type

CFPropertyListCreateDeepCopy fails to process array / dictionary containing NSNull

↘锁芯ラ 提交于 2019-12-10 05:23:05
问题 For some reason this sample code works: NSArray *immutable = @[ @"a", @"b", @"c" ]; NSMutableArray *mutable = (__bridge id)CFPropertyListCreateDeepCopy(kCFAllocatorDefault, (__bridge CFArrayRef)immutable, kCFPropertyListMutableContainers); and this code produces nil as a result of the conversion: NSArray *immutable = @[ @"a", [NSNull null], @"c" ]; NSMutableArray *mutable = (__bridge id)CFPropertyListCreateDeepCopy(kCFAllocatorDefault, (__bridge CFArrayRef)immutable,

CFPropertyListCreateDeepCopy returns nil if any value is NULL

和自甴很熟 提交于 2019-12-10 04:23:07
问题 I am using the following CoreFoundation function CFPropertyListCreateDeepCopy: for converting the immutable objects to mutable objects.If any of the object is NULL the CFPropertyListCreateDeepCopy returning empty .Is there any work around for this. self.packageArray = CFBridgingRelease(CFPropertyListCreateDeepCopy(NULL, (CFPropertyListRef)self.packageArray , kCFPropertyListMutableContainersAndLeaves)); CFPropertyListCreateDeepCopy fails to process array / dictionary containing NSNull sample

In Objective-C, how to print out N spaces? (using stringWithCharacters)

这一生的挚爱 提交于 2019-12-10 01:52:36
问题 The following is tried to print out N number of spaces (or 12 in the example): NSLog(@"hello%@world", [NSString stringWithCharacters:" " length:12]); const unichar arrayChars[] = {' '}; NSLog(@"hello%@world", [NSString stringWithCharacters:arrayChars length:12]); const unichar oneChar = ' '; NSLog(@"hello%@world", [NSString stringWithCharacters:&oneChar length:12]); But they all print out weird things such as hello ÔÅÓñüÔÅ®Óñü®ÓüÅ®ÓñüÔ®ÓüÔÅ®world ... I thought a "char array" is the same as a

CFDictionaryRef issues in Swift

牧云@^-^@ 提交于 2019-12-09 22:41:33
问题 I'm converting some of my older Objective-C code to Swift so I can move away from some deprecated methods but I keep getting a crash and so far I can't seem to figure out what's causing it. I'm getting a private key from a P12 Certificate and this method seems to work fine up until I get to the part where I actually need to get the dictionary from the CFArray, and even though the array has values in it the app keeps crashing. Here's the code that I have : func privateKeyFromCertificate

How to use CoreFoundation in QuickTime SDK for Windows?

夙愿已清 提交于 2019-12-08 19:29:25
Anybody can help me for compile this code in Cygwin / MingW / VS20(05|08|10)? Indeed i want to use CoreFoundation Framework in QuickTime SDK 7.3 for Windows. #include <stdio.h> #include <CoreFoundation.h> int main () { CFStringRef hello = CFSTR("Hello, world."); return 0; } i used this MakeFile for compile it, in Cygwin/MingW, but i get an error :( CC = gcc LDFLAGS = -L"C:/Program Files/QuickTime SDK/Libraries" -lQTMLClient CFLAGS = -Wall -mwindows -I"C:/Program Files/QuickTime SDK/CIncludes" all: StringExample.c $(CC) $(CFLAGS) $(LDFLAGS) -o StringExample StringExample.c -static Carefree