core-foundation

How do I use Apple's GameController framework from a macOS Command Line Tool?

十年热恋 提交于 2021-02-07 13:56:17
问题 I'm trying to get the following code to work as a macOS command line tool. It is important that this not be a Cocoa app, so that is not an option. This same code works perfectly in the same project with a Cocoa App target and detects a compatible controller, but when run as a Command Line Tool target, nothing happens and the API shows no controllers connected. Obviously, some of it is contrived... it's just the simplest I could boil it down to and have some indication of things happening when

Using CFArrayGetValueAtIndex in Swift with UnsafePointer (AUPreset)

拈花ヽ惹草 提交于 2020-01-24 13:50:14
问题 My problem is simple, but tricky. I want to write this line AUPreset *aPreset = (AUPreset*)CFArrayGetValueAtIndex(mEQPresetsArray, indexPath.row); in Swift. The trick is that the return value is UnsafePointer<Void> . 回答1: Have you tried this?: let aPreset = UnsafePointer<AUPreset>(CFArrayGetValueAtIndex(mEQPresetsArray, indexPath.row)) 回答2: Here's the Swift 4 version let aPreset = unsafeBitCast(CFArrayGetValueAtIndex(mEQPresetsArray, indexPath), to: AUPreset.self) 来源: https://stackoverflow

Test if screensaver is running or workspace is locked

旧时模样 提交于 2020-01-15 06:22:12
问题 On Mac OS X, I know in Cocoa I can set up a observer for detecting future screen saver events or workspace lock events, like this: - (id)init { if ((self = [super init])) { NSDistributedNotificationCenter* distCenter = [NSDistributedNotificationCenter defaultCenter]; [distCenter addObserver:self selector:@selector(onScreenSaverStarted:) name:@"com.apple.screensaver.didstart" object:nil]; [distCenter addObserver:self selector:@selector(onScreenSaverStopped:) name:@"com.apple.screensaver

Memory management of a CFErrorRef returned by ABRecordSetValue

 ̄綄美尐妖づ 提交于 2020-01-11 04:11:26
问题 Consider some typical CF code involving error handling, say something like this: ABRecordRef aRecord = ABPersonCreate(); CFErrorRef anError = NULL; ABRecordSetValue(aRecord, kABPersonFirstNameProperty, CFSTR("Joe"), &anError); How do I handle anError after this code? Do I have to retain it, to make sure it doesn't go away, and then later release it? Or am I already the owner and I only have to release it later? 回答1: In the Core Foundation framework, it's always the caller's responsibility to

Folding/Normalizing Ligatures (e.g. Æ to ae) Using (Core)Foundation

纵饮孤独 提交于 2020-01-10 19:45:09
问题 I am writing a helper that performs a number of transformations on an input string, in order to create a search-friendly representation of that string. Think of the following scenario: Full text search on German or French texts The entries in your datastore contain Müller Großmann Çingletòn Bjørk Æreogramme The search should be fuzzy, in that ull , Üll etc. match Müller Gros , groß etc. match Großmann cin etc. match Çingletòn bjö , bjo etc. match Bjørk aereo etc. match Æreogramme So far, I've

Difference between class property mVar and instance variable self.mVar

心已入冬 提交于 2020-01-09 10:51:49
问题 I am some what confused as to the difference between accessing an instance variable via self or just by name (when working inside the class). For instance, take this class: //In .h file: @interface Register : NSObject { NSString *mName; } - (id) initWithName:(NSString *) name; //In .m file: - (id) initWithName:(NSString *)name { if (self == [super init]) { mName = name; } return self; } What's the difference between accessing the instance variable via self.mName = name; vs mName = name; Which

How to programmatically retrieve UUID of root disk partition in OS X?

天涯浪子 提交于 2020-01-06 14:48:08
问题 I can retrieve an OS X disk partition UUID by this code: void PrintUUID() { DADiskRef disk; CFDictionaryRef descDict; DASessionRef session = DASessionCreate(NULL); if (session) { disk = DADiskCreateFromBSDName(NULL, session, "/dev/disk0s2"); if (disk) { descDict = DADiskCopyDescription(disk); if (descDict) { CFTypeRef value = (CFTypeRef)CFDictionaryGetValue(descDict, CFSTR("DAVolumeUUID")); CFStringRef strValue = CFStringCreateWithFormat(NULL, NULL, CFSTR("%@"), value); print(strVal); <------

Getting keyboard state using GetKeys function

蓝咒 提交于 2020-01-03 05:20:33
问题 Does anyone know how to get any key state (pressed or no) by GetKeys function? In other words how to handle this function: bool result = isPressed(kVK_LeftArrow); Thankyou. 回答1: The KeyMap type is an array of integers but its real layout is a series of bits, one per key code. The bit number for a particular key is one less than the virtual key code. Since bit-shifting isn't legal for very large values (e.g. you can't just ask the compiler to shift 74 bits), the KeyMap type is broken into 4

Safe way of iterating over an array or dictionary and deleting entries?

倾然丶 夕夏残阳落幕 提交于 2020-01-02 20:29:30
问题 I've heard that it is a bad idea to do something like this. But I am sure there is some rule of thumb which can help to get that right. When I iterate over an NSMutableDictionary or NSMutableArray often I need to get rid of entries. Typical case: You iterate over it, and compare the entry against something. Sometimes the result is "don't need anymore" and you have to remove it. But doing so affects the index of all the rows, doesn't it? So how could I safely iterate over it without accidently

CoreFoundation vs Foundation

空扰寡人 提交于 2019-12-31 08:24:11
问题 In iPhone development, speed is of the essence. Does anyone know if there is a speed difference between using a CoreFoundation type (like CFMutableDictionaryRef) versus a Foundation type (its counterpart, NSMutableDictionary). I would think manipulating the CF type would be faster as it doesnt have to throw around ObjC runtime messages, is this an unfounded assumption, has anyone actually looked in to this? 回答1: In a technical sense, yes, it is faster, for exactly that reason. In a practical