如何清除我的词典数据。它存储数据并每次都返回相同的消息

时间:2019-05-25 04:44:59

标签: swift dictionary

此函数存储第一个值并返回相同的消息。

我尝试过这个:

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.

1 个答案:

答案 0 :(得分:0)

要清除字典数据,您应该尝试:

myDictionary.removeAll()

或者您也可以尝试: 源自NSDictionary的removeAllObjects的{​​{1}}方法

NSMutableDictionary

因此,调用[myDictionary removeAllObjects]; [myDictionary release]; myDictionary = [[NSMutableDictionary alloc] init]; 将清空字典并释放所有包含的对象。