Allendar Allendar - 2 years ago 167
Swift Question

CFDictionary with unmanaged string?

I'm trying to make a prompt work for Accessibility in OS X, but the constant is a weird format and don't know how to make it work.

var options: [String:String] = [:]
options[kAXTrustedCheckOptionPrompt] = "YES"

The second line is obviously an error because of the conflicting type. How can I make the key work as that type or in what way should I cast it to work for the request method call?

Answer Source

You're passing the string "YES" when you mean to pass a boolean. You can't do that. Since this is the only value we're passing, we can let Swift do all the magical bridging for us from [String: Bool].

import Foundation
import ApplicationServices

var options: [String: Bool] = [:]
options[kAXTrustedCheckOptionPrompt.takeUnretainedValue() as String] = true
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download