在swift字典中找不到特定值的关键字



我试图从URLSession错误中获取tempFileName,并将resumeData解码到具有以下代码的字典中

let resumeDictionary = try! PropertyListSerialization.propertyList(from: data, options: [], format: nil) as? [AnyHashable : Any]

resumeDictionary包含以下字符串

[AnyHashable("$archiver"(:NSKeyedArchiver,AnyHashable("$objects"(:<__NSCFArray 0x2819140d0>($null{"类"="lt;CFKeyedArchiverUID 0x282221520[0x1dc4981b8]>{value=19}";;"NS.keys"=("lt;CFKeyedArchiverUID 0x282221320[0x1dc4981b8]>{value=2}";,"lt;CFKeyedArchiverUID 0x282221340[0x1dc4981b8]>{value=3}";,"lt;CFKeyedArchiverUID 0x282221360[0x1dc4981b8]>{value=4}";,"lt;CFKeyedArchiverUID 0x282221380[0x1dc4981b8]>{value=5}";,"lt;CFKeyedArchiverUID 0x2822213a0[0x1dc4981b8]>{value=6}";,"lt;CFKeyedArchiverUID 0x2822213c0[0x1dc4981b8]>{value=7}";,"lt;CFKeyedArchiverUID 0x2822213e0[0x1dc4981b8]>{value=8}";,"lt;CFKeyedArchiverUID 0x282221400[0x1dc4981b8]>{value=9}";);"NS.objects"=("lt;CFKeyedArchiverUID 0x282221420[0x1dc4981b8]>{value=10}";,"lt;CFKeyedArchiverUID 0x282221440[0x1dc4981b8]>{value=12}";,"lt;CFKeyedArchiverUID 0x282221460[0x1dc4981b8]>{value=13}";,"lt;CFKeyedArchiverUID 0x282221480[0x1dc4981b8]>{value=14}";,"lt;CFKeyedArchiverUID 0x2822214a0[0x1dc4981b8]>{value=15}";,"lt;CFKeyedArchiverUID 0x2822214c0[0x1dc4981b8]>{value=16}";,"lt;CFKeyedArchiverUID 0x2822214e0[0x1dc4981b8]>{value=17}";,"lt;CFKeyedArchiverUID 0x282221500[0x1dc4981b8]>{value=18}";);},NSURLSessionResumeCurrentRequest、NSURLSsessionResumeOriginal Request、NSURLSessionDownloadURL,NSURLSessionResumeInfoTempFileName,NSURLSsessionResumeByteReceived,NSURLSessionResumeEntityTag,NSURLSsessionResumeInfoVersion,NSURLSession ResumeServer下载日期{"类"="lt;CFKeyedArchiverUID 0x282221540[0x1dc4981b8]>{value=11}";;"NS.data"={长度=2427,字节=0x62706c69 73743030 d4010203 04050607…000000000000083b};},{"类"=(NSMutableData,NSData,NSObject);"类名"=NSMutableData;},{"类"="lt;CFKeyedArchiverUID 0x282221540[0x1dc4981b8]>{value=11}";;"NS.data"={长度=1666,字节=0x62706c69 73743030 d4010203 04050607…0000000000000594};},https://file-examples-com.github.io/uploads/2017/04/file_example_MP4_1280_10MG.mp4,CFNetworkDownload_BVLTmU.tmp,871422,";5f074cdf-962771";,2009年4月5日2020年7月16:59:11 GMT{"类"=(NSMutableDictionary,NSDictionary,NSObject);"类名"=NSMutableDictionary;}(,AnyHashable("$top"(:{NSKeyedArchiveRootObjectKey="<CFKeyedArchiverUID 0x2822212c0[0x1dc4981b8]>{value=1}";},AnyHashable("$版本"(:100000]

我想要在这个字符串中的值是"CFNetworkDownload_BVLTmU.tmp";我不知道如何在代码中获得它我看不到它的任何关键值有人能帮我吗?

如果我做对了,你正试图根据某个特定元素的值将其查找到Dictionary<AnyHasable, Any>中……然后你必须依赖first(where:),并在闭包中将元素的值类型转换为你要查找的值的类型(必须符合Equatable(,然后检查是否相等。

类似于:

if let element = dictionary.first(where: { ($0 as? Int) == valueToFind }) {
// do what you have to do with such element…
}

相关内容

  • 没有找到相关文章

最新更新