core-foundation

When do these objects get released under ARC?

南笙酒味 提交于 2019-12-21 20:18:36
问题 I have a few questions about ARC (automatic reference counting): CFURLRef url = (__bridge CFURLRef)[NSURL fileURLWithPath:appPath]; //Question 1: Here, I would expect the NSURL object to be autoreleased and //therefore the CFURLRef will also be available for “a while.” Is this correct? url = NULL; //Question 2: Will this cause the NSURL to be released immediately? NSURL *url = [NSURL fileURLWithPath:appPath]; url = nil; //Question 3: Does the “url = nil” result in an immediate release of the

NSString is exactly the same as CFString?

丶灬走出姿态 提交于 2019-12-21 09:39:10
问题 O'Reilly's Programming iOS 5 says (maybe in a looser sense), that "an NSString is a CFString". But is it true that at least NSString * will point to some memory chunk with an isa , while CFStringRef probably does not? 回答1: Not exactly the same; they are Toll-Free Bridged . This Apple Doc should explain in more detail. Here is even more detail from iOS 5 Programming Pushing The Limits on Google Books. 来源: https://stackoverflow.com/questions/12641189/nsstring-is-exactly-the-same-as-cfstring

CGEventTapCreate breaks down mysteriously with “key down” events

人盡茶涼 提交于 2019-12-21 04:52:25
问题 I'm using CGEventTapCreate to "steal" media keys from iTunes when my app is running. The code inside of the callback that I pass to CGEventTapCreate examines the event, and if it finds that it's one of the media keys, posts an appropriate notification to the default notification center. Now, this works fine if I post a notification for the "key up" event. If I do that for "key down" events, eventually my app stops getting media key events and iTunes takes over. Any ideas on what can be

Set non-owned window always on top - Like the app “Afloat”

社会主义新天地 提交于 2019-12-21 03:46:46
问题 I have set up a global hotkey with RegisterEventHotkey . When the user presses it, it gets the currently focused window with CGWindowListCopyWindowInfo , and then I need to set it always on top. If the current window is in my process (from which I am executing the code) I can simply convert the windowNumber from CGWindowListCopyWindowInfo to a NSWindow and do setLevel : nswin = [NSApp windowWithWindowNumber:windowNumber] [nswin setLevel: Int(CGWindowLevelForKey(kCGFloatingWindowLevelKey))] My

Is there a constant for the maximum CGFloat value?

无人久伴 提交于 2019-12-20 10:16:08
问题 I need to create a CGSize to compute text height of an arbitrary text with arbitrary length. UIKit has this nice method -sizeWithFont:constrainedToSize: and my text is only constrained in width, but not in height. For this, I need to set the maximum possible CGFloat for the height. Is there a constant like "CGFloatMax"? 回答1: CGGeometry defines: #define CGFLOAT_MAX FLT_MAX 回答2: For those using Swift 2, you should use: CGFloat.max For those using Swift 3, you should use: CGFloat

CFRunLoopRunInMode is exiting with code 1, as if nothing was added

安稳与你 提交于 2019-12-20 06:23:38
问题 I have created a CGEventTap like this: GetCurrentProcess(psn); var mask = 1 << kCGEventLeftMouseDown | // CGEventMaskBit(kCGEventLeftMouseDown) 1 << kCGEventLeftMouseUp | 1 << kCGEventRightMouseDown | 1 << kCGEventRightMouseUp | 1 << kCGEventOtherMouseDown | 1 << kCGEventOtherMouseUp | 1 << kCGEventScrollWheel; mouseEventTap = CGEventTapCreateForPSN(&psn, kCGHeadInsertEventTap, kCGEventTapOptionDefault, mask, null); if (!mouseEventTap.isNull()) { aRLS = CFMachPortCreateRunLoopSource

What is NSSearchPathForDirectoriesInDomains?

偶尔善良 提交于 2019-12-18 12:52:44
问题 [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] I used to know that sending a message to the object is kind of calling the method. However, I can't recognize what is NSSearchPathForDirectoriesInDomains . Is it C style function? If yes then why among all message style calls we have thing kind of function? 回答1: Yes, it's a plain C function taking and returning objective-c objects. As to the why... Apple probably didn't find a nice class to put it in.

CFRunLoopRun() vs [NSRunLoop run]

别说谁变了你拦得住时间么 提交于 2019-12-18 03:12:26
问题 I have an NSRunLoop object, to which I attach timers and streams. It works great. Stopping it is another story alltogether. I run the loop using [runLoop run] . If I try to stop the loop using CRunLoopStop([[NSRunLoop currentRunLoop] getCFRunLoop]) , the loop won't stop. If I start the loop using CRunLoopRun() instead, it works. I have also made sure that the call is made on the correct thread (the one running my custom run loop). I have debugged this with pthread_self() . I found a mailing

JavaScriptCore console.log

不打扰是莪最后的温柔 提交于 2019-12-18 03:04:32
问题 I've put together a very simple program that uses JavaScriptCore to evaluate JS: #import <CoreFoundation/CoreFoundation.h> #import <JavaScriptCore/JavaScriptCore.h> int main(int argc, const char * argv[]) { JSGlobalContextRef ctx = JSGlobalContextCreate(NULL); FILE *f = fopen(argv[1],"r"); char * buffer = malloc(10000000); fread(buffer,1,10000000,f); CFStringRef strs = CFStringCreateWithCString(NULL, buffer, kCFStringEncodingASCII); JSStringRef jsstr = JSStringCreateWithCFString(strs);

JavaScriptCore console.log

情到浓时终转凉″ 提交于 2019-12-18 03:04:03
问题 I've put together a very simple program that uses JavaScriptCore to evaluate JS: #import <CoreFoundation/CoreFoundation.h> #import <JavaScriptCore/JavaScriptCore.h> int main(int argc, const char * argv[]) { JSGlobalContextRef ctx = JSGlobalContextCreate(NULL); FILE *f = fopen(argv[1],"r"); char * buffer = malloc(10000000); fread(buffer,1,10000000,f); CFStringRef strs = CFStringCreateWithCString(NULL, buffer, kCFStringEncodingASCII); JSStringRef jsstr = JSStringCreateWithCFString(strs);