kSecSharedPassword is unusable in Swift

Originator:tangphillip
Number:rdar://18189750 Date Originated:31-Aug-2014 04:18 PM
Status:Closed Resolved:
Product:iOS SDK Product Version:Xcode Version 6.0 (6A280e), iOS 8 SDK, beta 5
Classification: Reproducible:Always
 
Summary:
It is impossible to using Core Foundation collections directly in Swift, because `CFDictionaryGetValue`, `CFArrayGetValueAtIndex`, etc return `UnsafePointer` (and you can't downcast that to anything useful). So, we're stuck casting the collection to its bridged Foundation counterpart.

Which leads us to the problem: kSecSharedPassword is declared as `Unmanaged<AnyObject>!` in the Swift header. Since `kSecSharedPassword` is meant to be used as a key to a dictionary, it should be declared as NSCopying.

Steps to Reproduce:
Attempt to get a password with `SecRequestSharedWebCredential()` in Swift. You'll end up with code that looks a bit like this:

SecRequestSharedWebCredential(nil, nil) { (cfCredentialsArray: CFArray!, error: CFError!) -> Void in
    let credentialsArray = cfCredentialsArray as NSArray
    if let credentials = credentialsArray.objectAtIndex(0) as? NSDictionary {
        let username = credentials[kSecAttrAccount] as? String
        let password = credentials[kSecSharedPassword] as? String
        let service = credentials[kSecAttrService] as? String
        NSLog("username: %@, password: %@, service: %@", username, password, service)
    }
}

Expected Results:
The code should compile.

Actual Results:
>> let password = credentials[kSecSharedPassword] as? String

Type 'Unmanaged<AnyObject>!' does not conform to protocol 'NSCopying'

Version:
Xcode Version 6.0 (6A280e), iOS 8 SDK, beta 5

Notes:


Configuration:
iPhone 5s Verizon

Attachments:

Comments

This issue has been verified as resolved and can be closed.

By tangphillip at May 9, 2016, 10:07 p.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!