core-foundation

How would I add only business days to an NSDate?

心不动则不痛 提交于 2019-12-03 11:03:51
问题 I have an issue related to calculating business days in Objective-C. I need to add X business days to a given NSDate . For example, if I have a date: Friday 22-Oct-2010 , and I add 2 business days, I should get: Tuesday 26-Oct-2010 . Thanks in advance. 回答1: There are two parts to this: Weekends Holidays I'm going to pull from two other posts to help me out. For weekends, I'm going to need to know a given date's day of the week. For that, this post comes in handy: How to check what day of the

How to convert CFArray to Swift Array?

和自甴很熟 提交于 2019-12-03 10:55:18
问题 According to Apple's "Using Swift with Cocoa and Objective-C", "In Swift, you can use each pair of toll-free bridged Foundation and Core Foundation types interchangeably". This makes working with Core Foundation sound way simpler than it actually is... I am trying to work with a CFArray that is returned from CoreText. I have this code: let lines: CFArrayRef = CTFrameGetLines(frame) I see two possible ways to access members of this array. Neither is working for me right now. Way #1 - Use the

Is it safe to schedule and invalidate NSTimers on a GCD serial queue?

我怕爱的太早我们不能终老 提交于 2019-12-03 06:33:06
What's the right way to do this? The NSTimer documentation says this: Special Considerations You must send this message from the thread on which the timer was installed. If you send this message from another thread, the input source associated with the timer may not be removed from its run loop, which could prevent the thread from exiting properly. Since GCD doesn't assure you that a serial queue will always run blocks on the same thread, what's the right way to ensure that you schedule and invalidate an NSTimer on the same thread? EDIT: Following the advise of the answer below, I created

Getting “global” mouse position in Mac OS X

六眼飞鱼酱① 提交于 2019-12-03 04:43:49
问题 How can I get in Mac OS X "global" mouse position - I mean how can I in cocoa/cf/whatever find out cursor position even if it's outside the window, and even if my window is inactive? I know it's somehow possible (even without admin permissions), because I've seen something like that in Java - but I want to write it in ObjC Sorry for my English - I hope you'll understand what I mean ;) 回答1: NSPoint mouseLoc; mouseLoc = [NSEvent mouseLocation]; //get current mouse position NSLog(@"Mouse

Releasing Core Foundation object references

天涯浪子 提交于 2019-12-03 03:47:25
问题 Do I need to release a Core Foundation objects to clear up memory? And if so, how? For example, in the code: ABAddressBookRef addressBook = ABAddressBookCreate(); CFArrayRef peopleArray = ABAddressBookCopyArrayOfAllPeople(addressBook); do I need to release peopleArray ? What about addressBook ? 回答1: Yes, in CoreFoundation you have to release anything with Create or Copy in the name. You do this with CFRelease(). In your case, you should be releasing both the array and the address book

strong @property with __attribute__((NSObject)) for a CF type doesn't retain

不打扰是莪最后的温柔 提交于 2019-12-03 02:24:22
问题 UPDATE: This issue has been fixed as of Xcode 4.6! This technique now works as intended again. However, make sure to read the notes at the top of Rob Napier's excellent answer before you use it in your code. ORIGINAL POST (ARC, Xcode 4.3.1, iOS 5.1) I have a strong property of a CF type (CGImage) that I want to be automatically managed by ARC using __attribute__((NSObject)) (as in having retain & release in the synthesized setter, and it being nil'ed in dealloc), but it doesn't work: the

How would I add only business days to an NSDate?

这一生的挚爱 提交于 2019-12-03 00:33:28
I have an issue related to calculating business days in Objective-C. I need to add X business days to a given NSDate . For example, if I have a date: Friday 22-Oct-2010 , and I add 2 business days, I should get: Tuesday 26-Oct-2010 . Thanks in advance. Steve There are two parts to this: Weekends Holidays I'm going to pull from two other posts to help me out. For weekends, I'm going to need to know a given date's day of the week. For that, this post comes in handy: How to check what day of the week it is (i.e. Tues, Fri?) and compare two NSDates? For holidays, @vikingosegundo has a pretty great

How to retrieve the values for the particular key from CFMutableDictionary

╄→гoц情女王★ 提交于 2019-12-02 22:19:15
问题 In C++ EventType.find(1)->second can be used to find the value for the key 1. I am new to Objective C.I have implemented CFDictionary to addvalue onto it.But how do i retreive and view the values of the particular key. EDITED: CFNumberRef tId = CFNumberCreate(NULL,kCFNumberShortType,&st); CFDictionarySetValue(cfdict,tId,st); NSLog(@"The value is:%s",(CFDictionaryGetValue(cfdict,tId))); Its running without error but i could not get the output. 回答1: The documentation for CFMutableDictionary

Swift: Extracting / downcasting CFType based CoreText types in a CFArray

杀马特。学长 韩版系。学妹 提交于 2019-12-02 19:36:20
问题 I am trying to port elements of the CoreAnimationText sample to Swift. I cannot figure out though, how to extract or downcast the elements of CTRun from an array, in order to pass them to functions that expect and act upon the Swift-ified CTRun type. I either get runtime errors or linking errors from the playground snippet below import CoreText import QuartzCore let text = NSAttributedString(string: "hello") var line: CTLine = CTLineCreateWithAttributedString(text) var ctRuns:CFArray =

Getting “global” mouse position in Mac OS X

走远了吗. 提交于 2019-12-02 18:41:07
How can I get in Mac OS X "global" mouse position - I mean how can I in cocoa/cf/whatever find out cursor position even if it's outside the window, and even if my window is inactive? I know it's somehow possible (even without admin permissions), because I've seen something like that in Java - but I want to write it in ObjC Sorry for my English - I hope you'll understand what I mean ;) NSPoint mouseLoc; mouseLoc = [NSEvent mouseLocation]; //get current mouse position NSLog(@"Mouse location: %f %f", mouseLoc.x, mouseLoc.y); If you want it to continuously get the coordinates then make sure you