26986


Objective-CからSwiftに書き直しているのですがうまく書き直せません。

# Objective-C

[code]

    NSMutableDictionary * queryPublicKey = [[NSMutableDictionary alloc] init];
    [queryPublicKey setObject:(__bridge id)kSecClassKey forKey:(__bridge id)kSecClass];
    [queryPublicKey setObject:publicTag forKey:(__bridge id)kSecAttrApplicationTag];
    [queryPublicKey setObject:(__bridge id)kSecAttrKeyTypeRSA forKey:(__bridge id)kSecAttrKeyType];
    
[/code]

# Swift

[code]

    var queryPublicKey = NSMutableDictionary()
        queryPublicKey = [kSecClass: kSecClassKey,
                          kSecAttrApplicationTag: keychainIdentifierData,
                          kSecAttrKeyType: kSecAttrKeyTypeRSA]
    
[/code]

Objective-Cを元に書き直すと

> 「Value of type 'CFString' does not conform to expected dictionary key type
> 'NSCopying'」

とエラーを吐きます。  
何かしら一手間必要なのでしょうか。


CC BY-SA 3.0
2016-06-23T03:23:45.797
26978
2016-06-23T06:04:47.883
16765
question
swift xcode swift2 xcode7
Objective-CからSwiftへの変換

[code]

    var queryPublicKey = NSMutableDictionary()
    queryPublicKey = [kSecClass as NSString: kSecClassKey,
                      kSecAttrApplicationTag as NSString: keychainIdentifierData,
                      kSecAttrKeyType as NSString: kSecAttrKeyTypeRSA]
    
[/code]

`CFString` を `NSString` にキャストする必要があります。


CC BY-SA 3.0
2016-06-23T06:04:47.883
26986
2016-06-23T06:04:47.883
5337
26978
answer