阅读 Apple 的代码,我看到了以下内容(谈论钥匙串服务):
query[kSecAttrService as String] = service as AnyObject?
的目的是AnyObject?
什么?
我认为它可以简化为
query[kSecAttrService as String] = service as AnyObject
有什么线索吗?
这是来自 Apple 示例的整个片段:
private static func keychainQuery(withService service: String, account: String? = nil, accessGroup: String? = nil) -> [String : AnyObject] {
var query = [String : AnyObject]()
query[kSecClass as String] = kSecClassGenericPassword
query[kSecAttrService as String] = service as AnyObject?
if let account = account {
query[kSecAttrAccount as String] = account as AnyObject?
}
if let accessGroup = accessGroup {
query[kSecAttrAccessGroup as String] = accessGroup as AnyObject?
}
return query
}