0
ここで私がキー値のペアtitle
がDiscount
で始まる単語を持っているかどうかを調べる必要のあるモデルクラスからJsonデータを取得しています。たとえば、Discount
で始まるキー値のペアが見つかった場合特定のテーブルを設定する必要があります表示セルのラベルDiscount
どのようにキー値のペアからそれを見つける誰も私を助けることができますこれを実装する方法?ここではここ迅速な名前で特定のキー値を見つける方法3?
は私のモデルクラスのデータである
struct TotalPriceSegments {
let code : String?
let title : String?
let value : Double?
init(json: [String:Any]) {
self.code = json["code"] as? String
self.title = json["title"] as? String
self.value = json["value"] as? Double
}
}
テーブルビューコードcellForRow方法で
let cell = tableView.dequeueReusableCell(withIdentifier: "checkout", for: indexPath) as! CheckoutTableViewCell
let array = totalPriceModel?.totalSegments[indexPath.row]
cell.titleLabel.text = array?.title
let total = doubleToStringDecimalPlacesWithDouble(number: Double((array?.value)!), numberOfDecimalPlaces: 2)
cell.valueLabel.text = (String(describing:("$ \(total)")))
return cell
可能な重複辞書キーと値を知ることなく値](https://stackoverflow.com/questions/26989443/swift-reference-to-a-dictionary-kアイ・アンド・バリュー・アウェイ・ノウハウ・キー) – dcorking