core-foundation

Is there a method to generate a standard 128bit GUID (UUID) on the Mac?

时光总嘲笑我的痴心妄想 提交于 2019-11-28 19:05:31
问题 Is there a built in function equivalent to .NET's Guid.NewGuid(); in Cocoa? My desire is to produce a string along the lines of 550e8400-e29b-41d4-a716-446655440000 which represents a unique identifier. 回答1: UUIDs are handled in Core Foundation, by the CFUUID library. The function you are looking for is CFUUIDCreate. FYI for further searches: these are most commonly known as UUIDs, the term GUID isn't used very often outside of the Microsoft world. You might have more luck with that search

Toll-free bridging and pointer access in Swift

回眸只為那壹抹淺笑 提交于 2019-11-28 18:44:15
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)(host), port, \ &readStream, &writeStream); NSInputStream inputStream = (__bridge_transfer

Why doesn't this simple CoreMIDI program produce MIDI output?

老子叫甜甜 提交于 2019-11-28 17:36:08
问题 Here is an extremely simple CoreMIDI OS X application that sends MIDI data. The problem is that it doesn't work. It compiles fine, and runs. It reports no errors, and does not crash. The Source created becomes visible in MIDI Monitor. However, no MIDI data comes out . Could somebody let me know what I'm doing wrong here? #include <CoreMIDI/CoreMIDI.h> int main(int argc, char *args[]) { MIDIClientRef theMidiClient; MIDIEndpointRef midiOut; MIDIPortRef outPort; char pktBuffer[1024];

Generate a UUID on iOS from Swift

社会主义新天地 提交于 2019-11-28 15:07: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? Ahmed Al Hafoudh Try this one: let uuid = NSUUID().uuidString print(uuid) Swift 3/4 let uuid = UUID().uuidString print(uuid) 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.UUIDString . Note that NSUUID is available from iOS 6 and up. For Swift 4 ; let uuid = NSUUID()

ios User Prompt when making outgoing call via URL Scheme 10.2+

ぐ巨炮叔叔 提交于 2019-11-28 14:15:47
It appears that Apple have changed the behaviour when making a phone call via the URL Scheme. We currently use this code to initiate a phone call: let url = NSURL(string: "tel://011111111111") UIApplication.sharedApplication().openURL() Prior to iOS 10.2, this immediately launched the dialler and placed the phone call. It appears that this has now changed, and the user receives a prompt to confirm to make the phone call. It appears tel:// is behaving more like telprompt://. This is despite the official Apple URL Scheme document (last updated 2015) mentioning that user interaction is not

How to convert a classic HFS path into a POSIX path

☆樱花仙子☆ 提交于 2019-11-28 11:43:16
问题 I am reading old files that still use HFS style paths, such as VolumeName:Folder:File . I need to convert them into POSIX paths. I do not like to do string replacement as it is a bit tricky, nor do I want to invoke AppleScript or Shell operations for this task. Is there a framework function to accomplish this? Deprecation is not an issue. BTW, here's a solution for the inverse operation. 回答1: A solution in Obj-C and Swift as category / extension of NSString / String . The unavailable

Xcode 7 Beta 6, dyld ___NSArray0__ crash

徘徊边缘 提交于 2019-11-28 09:21:59
For the first time I was able to compile my app in Xcode 7 (failed in beta 4 and 5). So, thats good progress I guess. However, when i load my app on my iPhone 6, iOS 8.4.1, it crashed in the debugger with the following message: dyld: Symbol not found: _NSArray0 Referenced from: /private/var/mobile/Containers/Bundle/Application/0294DF62-AE80-485D-BB11-8C3A5D39777D/Boxtiq.app/Boxtiq Expected in: /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation in /private/var/mobile/Containers/Bundle/Application/0294DF62-AE80-485D-BB11-8C3A5D39777D/Boxtiq.app/Boxtiq Is this something to do with

Testing file existence using NSURL

五迷三道 提交于 2019-11-28 04:03:08
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 explicitly guaranteed to not exist if the file doesn't, and some of them (e.g., NSURLEffectiveIconKey )

OSX FSEventStreamEventFlags not working correctly

 ̄綄美尐妖づ 提交于 2019-11-28 02:59:50
问题 I am watching a directory for file system events. Everything seems to work fine with one exception. When I create a file the first time, it spits out that it was created. Then I can remove it and it says it was removed. When I go to create the same file again, I get both a created and removed flag at the same time. I obviously am misunderstanding how the flags are being set when the callback is being called. What is happening here? // // main.c // GoFSEvents // // Created by Kyle Cook on 8/22

assign properties, ARC and Core Foundation objects

人走茶凉 提交于 2019-11-27 20:56:28
Edit 2. Thanks to Ken this is now working. And I even think I understand why :-) Here's the amended line: - (void) reCreatePath { CGMutablePathRef p = ::CGPathCreateMutable() ; ::CGPathMoveToPoint (p, 0, TL.x, TL.y) ; // [snip] ::CGPathAddLineToPoint (p, 0, BL.x, BL.y) ; ::CGPathCloseSubpath(p) ; self.path = p ; ::CGPathRelease(p) ; // <<== THIS IS IT!! :-) } Edit. I still don't get it. I tried Chuck suggestion: @property (nonatomic, strong) __attribute__((NSObject)) CGPathRef path ; Like so: @interface TopLeftSlidingView () @property (nonatomic, strong) __attribute__((NSObject)) CGPathRef