Swift-4:如何将NSDrray的NSDray值分配给另一个NSDictionary变量,以及如何从NSDictionary获取key的值

时间:2018-04-18 05:36:47

标签: swift tableview swift4

在目标C中,我们将字典值的NSArray分配给NSDictionary变量并获取密钥的值,如下所示NSDictionary *dictValue = [array objectAtIndex:indexPath.row]cell.name.text = [dictValue valueForKey:"customer_name"],以便如何在swift-4中进行上述编码。我声明NSArray变量的方式,将字典值数组绑定到另一个NSDictionary以及从NSDictionary获取值的方法。

var leadsArray = [NSArray]() /* Declared NSArray Variable */
let dictValue = larray[indexPath.row] as NSDictionary! /* Assigning each array of dictionary by row count */
cell.label1.text = dictValue["customer_name"] /* Getting valuefor key from NSDictionary Varibale */

2 个答案:

答案 0 :(得分:0)

试试这个

var dictValue = array[indexPath.row] as? [AnyHashable: Any]
cell.name.text = dictValue?["customer_name"]

答案 1 :(得分:0)

您可以使用:

let arrResponse = yourRespons as! [String:Any]

let name = arrResponse["customer_name"] as! String
print(name)