swift - 如何清除我的字典数据。它存储数据并每次返回相同的消息
问题描述
此函数存储第一个值并返回相同的消息。
我试过这个:
FileManager.default.clearTmpDirectory()
let resultt:NSDictionary = dict! as NSDictionary
//let topup = resultt.value(forKeyPath: "Body.QR_TopupResponse.QR_TopupResult") as! String
func getdata () -> String{
guard let body = resultt["Body"] as? [String: Any] else {
// Failed to find body, return empty string
return ""
}
guard let response = body["QR_TopResponse"] as? [String: Any] else {
return ""
}
guard let result = response["QR_ToResult"] as? String else {
return ""
}
return result
}
print(getdata())
self.presentAlert(withTitle: "", message: getdata())
or ..
var ftsm = resultsm.value(forKeyPath:
"Body.QR_TOPResponse.QR_TOPResult") as! String
// How to remove keypath.
解决方案
要清除字典数据,您应该尝试:
myDictionary.removeAll()
或者您也可以尝试:
removeAllObjects
方法NSMutableDictionary
源自 NSDictionary
[myDictionary removeAllObjects];
[myDictionary release];
myDictionary = [[NSMutableDictionary alloc] init];
因此,调用-removeAllObjects
将清空字典并释放所有包含的对象。
推荐阅读
- reactjs - 无法读取 VueJS 中未定义的属性“displayName”
- php - 我通过邮递员将原始 JSON 数据发送到 PHP 函数(PUT 方法)。file_get_contents('php://input') 给出 null
- reactjs - 它不起作用有人可以提出任何建议吗?
- javascript - 如何从文本字段中获取文本
- javascript - 使用 useState 设置的 Api 调用不会及时更新以设置为 useRef 挂钩
- php - 具有可变排序标准的多维排序
- javascript - TouchableOpacity 单击时更改文本的颜色
- java - 如何在 Spring 中从 RestController 返回 HTML 页面?
- python - macbook 中的 localhost 在 python 中用于 MongoDB pymongo
- entity-framework-core - 使用 EF Core 和 AutoMapper.Collections 更新实体的问题