我的要求似乎在工作:
let queryAttributes = NSDictionary(objects: [kSecclassGenericPassword,"MyService","MyAccount",true],forKeys: [kSecclass,kSecAttrService,kSecAttrAccount,kSecReturnData])dispatch_async(dispatch_get_global_queue( disPATCH_QUEUE_PRIORITY_DEFAulT,0),{ var dataTypeRef : Unmanaged<AnyObject>? let status = SecItemcopyMatching(queryAttributes,&dataTypeRef); let retrIEvedData : NSData = dataTypeRef!.takeRetainedValue() as NSData *** ^^^^can't compile this line^^^^})
我的问题是,代码不会编译:
Bitcast requires both operands to be pointer or neither %114 = bitcast %objc_object* %113 to %PSs9AnyObject_,!dbg !487Bitcast requires both operands to be pointer or neither %115 = bitcast %PSs9AnyObject_ %114 to i8*,!dbg !487LLVM ERROR: broken function found,compilation aborted!
我不知道如何转换非托管的< AnyObject>到NSData。
有任何想法吗?
使用withUnsafeMutablePointer函数和UnsafeMutablePointer结构来检索数据,如下所示:var result: AnyObject?var status = withUnsafeMutablePointer(&result) { SecItemcopyMatching(queryAttributes,UnsafeMutablePointer()) }if status == errSecSuccess { if let data = result as NSData? { if let string = Nsstring(data: data,enCoding: NSUTF8StringEnCoding) { // ... } }}
它发布(Fastest [-O])构建工作正常。
总结以上是内存溢出为你收集整理的使用Swift查询iOS钥匙串全部内容,希望文章能够帮你解决使用Swift查询iOS钥匙串所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)