On 26 Sep 2016, at 10:48, Quinn The Eskimo! via swift-users 
<[email protected]> wrote:

> Next, unless you absolutely have to, I’d avoid getting between 
> IOServiceMatching and IOServiceAddMatchingNotification.  These two have 
> unusual memory management behaviour (IOServiceMatching returns a +1 reference 
> and IOServiceAddMatchingNotification consumes that reference).  It looks like 
> the current SDK has the right annotations for this but it’s still easy to run 
> into trouble.

And, and if you do get between these two it’s probably easiest to work in 
‘CFDictionary space’ rather than try to treat this stuff as a Swift dictionary. 
 This will help:

func CFDictionarySetValue(_ dict: CFMutableDictionary, _ key: String, _ 
valueObj: AnyObject) {
    let keyObj = key as NSString
    withExtendedLifetime(keyObj) {
        CFDictionarySetValue(dict, Unmanaged.passUnretained(keyObj).toOpaque(), 
Unmanaged.passUnretained(valueObj).toOpaque())
    }
}

Share and Enjoy
--
Quinn "The Eskimo!"                    <http://www.apple.com/developer/>
Apple Developer Relations, Developer Technical Support, Core OS/Hardware


_______________________________________________
swift-users mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-users

Reply via email to