How to call SecItemCopyMatching in Xcode 7 beta 4?

后端 未结 2 1440
终归单人心
终归单人心 2021-02-09 09:14

In previous versions of Xcode 6 and 7 with Swift, this syntax would work:

    var secureItemValue: Unmanaged?

    let statusCode: OSStatus = Se         


        
相关标签:
2条回答
  • 2021-02-09 10:04

    This works on Xcode 7 beta 4

    var dataTypeRef: AnyObject?
    
        let status: OSStatus = withUnsafeMutablePointer(&dataTypeRef) { SecItemCopyMatching(keychainQuery as CFDictionaryRef, UnsafeMutablePointer($0)) }
    
        if status == noErr {
            return dataTypeRef as? NSData
        }
        else {
            return nil
        }
    
    0 讨论(0)
  • 2021-02-09 10:11

    According to this answer you can just remove Unmanaged<> around AnyObject:

    var secureItemValue: AnyObject?
    
    let statusCode: OSStatus = SecItemCopyMatching(keychainItemQuery, &secureItemValue)
    
    0 讨论(0)
提交回复
热议问题