core-foundation

CFURLCreateDataAndPropertiesFromResource deprecated. And looking for substitute

前提是你 提交于 2019-12-01 06:54:52
问题 Along with a bunch of other things included in Apple's Load Preset Demo sample code, the call to CFURLCreateDataAndPropertiesFromResource is now deprecated. But I can't find a substitute for it - neither an option-click nor a look at the reference tell me any more than that it is no longer the done thing. CFDataRef propertyResourceData = 0; Boolean status; SInt32 errorCode = 0; OSStatus result = noErr; // Read from the URL and convert into a CFData chunk status =

Modifying Image Metadata

杀马特。学长 韩版系。学妹 提交于 2019-12-01 04:23:12
问题 I’m trying to modify the metadata contained in a JPEG image. It can be any of the metadata in the image, in my example I’m attempting to change to DateTimeDigitized property to the current date. My code seems to mostly work, however the set property is being removed rather than changed. I’m not certain why this is happening, can anyone tell me what I’m doing wrong? I’d welcome any advice on frameworks that can help perform the task but I’d especially be interested in what I’m doing

Determining what a CFTypeRef is?

纵饮孤独 提交于 2019-12-01 03:50:55
I have a function which returns CFTypeRef . I have no idea what it really is. How do I determine that? For example it might be a CFStringRef . CFGetTypeID() : if (CFGetTypeID(myObjectRef) == CFStringGetTypeID()) { //i haz a string } The short answer is that you can (see Dave DeLongs answer). The long answer is that you can't. Both are true. A better question might be "Why do you need to know?" In my opinion, if you can arrange things so that you don't need to know, you're probably going to be better off. I'm not saying that you can't do it, or even that you shouldn't. What I am saying is that

Get NSWindow* from CGWindowListCopyWindowInfo

泄露秘密 提交于 2019-12-01 02:42:18
问题 I have accomplished listing all the windows (in z order from front to back I think/hope) using CGWindowListCopyWindowInfo but I am having an issue getting the NSWindow* from it so I can use with orderFront: etc. It seems I don't even get CGWindowID from it. This is my code, it is js-ctypes. var cfarr_win = ostypes.API('CGWindowListCopyWindowInfo')(ostypes.CONST.kCGWindowListOptionAll | ostypes.CONST.kCGWindowListExcludeDesktopElements, ostypes.CONST.kCGNullWindowID); var cnt_win = ostypes.API

Memory management of a CFErrorRef returned by ABRecordSetValue

烈酒焚心 提交于 2019-12-01 01:27:28
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? In the Core Foundation framework, it's always the caller's responsibility to release an error returned through a CFErrorRef * argument. For example here's a header file comment from

Determining what a CFTypeRef is?

不问归期 提交于 2019-12-01 01:07:11
问题 I have a function which returns CFTypeRef . I have no idea what it really is. How do I determine that? For example it might be a CFStringRef . 回答1: CFGetTypeID(): if (CFGetTypeID(myObjectRef) == CFStringGetTypeID()) { //i haz a string } 回答2: The short answer is that you can (see Dave DeLongs answer). The long answer is that you can't. Both are true. A better question might be "Why do you need to know?" In my opinion, if you can arrange things so that you don't need to know, you're probably

How can I find the path to a file in an application bundle (NSBundle) using C?

∥☆過路亽.° 提交于 2019-11-30 19:42:16
Is there a C API for finding the path to a file in an application bundle? I know that this can be done in Objective-C with the following syntax. NSString *path = [[NSBundle mainBundle] pathForResource:@"MyImage" ofType:@"bmp"]; Is there a corresponding function that I can call from C or C++ code, as well? Chris Frederick After Mike K pointed me in the right direction , I was able to retrieve the path to a file in an application bundle with the following code. // Get a reference to the main bundle CFBundleRef mainBundle = CFBundleGetMainBundle(); // Get a reference to the file's URL CFURLRef

Toll-free bridging and pointer access in Swift

隐身守侯 提交于 2019-11-30 06:27:33
问题 I am porting an App from Objective-C to Swift and I need to use the following method: CFStreamCreatePairWithSocketToHost(alloc: CFAllocator!, host: CFString!, port: UInt32, \ readStream: CMutablePointer<Unmanaged<CFReadStream>?>, \ writeStream: CMutablePointer<Unmanaged<CFWriteStream>?>) The old logic looks like this (which several web sites seem to agree on): CFReadStreamRef readStream = NULL; CFWriteStreamRef writeStream = NULL; CFStreamCreatePairWithSocketToHost(NULL, (__bridge CFStringRef

Generate a UUID on iOS from Swift

你说的曾经没有我的故事 提交于 2019-11-30 06:08:08
问题 In my iOS Swift app I want to generate random UUID ( GUID ) strings for use as a table key, and this snippet appears to work: let uuid = CFUUIDCreateString(nil, CFUUIDCreate(nil)) Is this safe? Or is there perhaps a better (recommended) approach? 回答1: Try this one: let uuid = NSUUID().uuidString print(uuid) Swift 3/4 let uuid = UUID().uuidString print(uuid) 回答2: You could also just use the NSUUID API: let uuid = NSUUID() If you want to get the string value back out, you can use uuid

Testing file existence using NSURL

僤鯓⒐⒋嵵緔 提交于 2019-11-30 05:55:18
问题 Snow Leopard introduced many new methods to use NSURL objects to refer to files, not pathnames or Core Services' FSRefs. However, there's one task I can't find a URL-based method for: Testing whether a file exists. I'm looking for a URL-based version of -[NSFileManager fileExistsAtPath:]. Like that method, it should return YES if the URL describes anything, whether it's a regular file, a directory, or anything else. I could attempt to look up various resource values, but none of them are