Using Unmanaged <AnyObject>! like key in NSMutableDictionary

I'm trying to create a keychain request, but I'm having difficulty using Item Attribute keys as dictionary keys. When creating a dictionary, I can pass attribute elements wrapped in an array, like dictionary keys, such as no problem

genericPasswordQuery = NSMutableDictionary(objects: [kSecClassGenericPassword, identifier], forKeys: [kSecClass, kSecAttrGeneric])

However, if I try to add another similar element to the dict request like this:

genericPasswordQuery.setObject(accessGroup, key:kSecAttrAccessGroup)

He complains that the key does not match NSCopying and delivers an error like:

"could not find an overload for 'setObject' that takes the supplied arguments

This is the standard implementation of SecItemAdd, but I am having problems with this in Swift.

+4
source share
1 answer

, . docs:

Swift API, , Core Foundation . Swift Core Foundation . Core Foundation .

API, , . , Swift . , - takeUnretainedValue() takeRetainedValue().

:

genericPasswordQuery = NSMutableDictionary(objects: [kSecClassGenericPassword, identifier], forKeys: [kSecClass, kSecAttrGeneric])

var kSecAttrAccessGroupSwift: NSString = kSecAttrAccessGroup.takeRetainedValue() as NSString
genericPasswordQuery.setObject(accessGroup, forKey: kSecAttrAccessGroupSwift)

Xcode, , .takeRetainedValue

+8

Source: https://habr.com/ru/post/1544546/


All Articles